您的位置:首页 > 编程语言 > Java开发

Java中排序相关

2013-11-12 00:00 253 查看
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(pa, from, to); 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(oa, from, to); Sorts the elements of the array, in the range from...to of an object type into ascending order.
Arrays.sort(oa, comp); Sorts the elements of the array of an object type into ascending order, using the Comparator comp.
Arrays.sort(oa, from, to, comp); 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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: