Java中排序相关

1. Array

基础类型可以直接sort

Method Description
Arrays sort methods
Arrays.sort(pa); Sorts the elements of the array of a primitive type into ascending order using their natural ordering.
Arrays.sort(pafromto); Sorts the elements pa[from]...pa[to-1] of a primitive type. into ascending order.
Arrays.sort(oa); Sorts the elements of the array of an object type into ascending order, using the order defined by Comparable interface, which defines thecompareTo method. Note that many Java classes such as String (but notStringBuffer), Double, BigInteger, etc implement Comparable.
Arrays.sort(oafromto); Sorts the elements of the array, in the range from...to of an object type into ascending order.
Arrays.sort(oacomp); Sorts the elements of the array of an object type into ascending order, using the Comparator comp.
Arrays.sort(oafromtocomp); Sorts the elements of the array, in the range from...to of an object type into ascending order using the Comparator comp.

2. ArrayList, 基础类直接调用Collections.sort方法。创建的对象要实现Comparable或者Comparator.

 


你可能感兴趣的:(Java中排序相关)