Java中排序相关
2013-11-12 00:00
253 查看
1. Array
基础类型可以直接sort
2. ArrayList, 基础类直接调用Collections.sort方法。创建的对象要实现Comparable或者Comparator.
基础类型可以直接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. |
相关文章推荐
- 剑指offer面试题java实现之题4之相关题目:两个排序数组合并
- Java功底篇系列-02-如何理解实际开发中与“排序”相关的问题
- Java中利用比较器对一个对象的相关属性的排序
- 【Java相关】Java中TreeSet和HashSet的排序和去重
- java相关总结4--冒泡、选择、快速、插入排序
- java 相关排序
- Java相关排序
- java:Comparable类的排序相关
- 我在学JAVA——排序、查找相关知识
- Java -------- 首字母相关排序总结
- Java基本功练习五(一维数组相关操作[声明、创建、乱序、排序、查找]和方法的重载举例[浅议])
- 数据结构java语言的各种排序
- 一步一步搞清排序之快速排序(JAVA)
- 【Java相关】二进制角度计算~0x99^0x66
- java中用递归将字符串做各种排序输出
- JAVA中运用数组的四种排序方法
- SSH实战 · JAVA发送邮件相关
- java实现简单二叉树排序
- java字符串API相关操作
- 直接插入排序——java