排序函数
Arrays.sort
Collections.sort
排序集合
TreeSet TreeMap
示例
public class Test1_1 {
private static Randomrandom =new Random();
public static void main(String[] args) {
int size =10000;
Integer[] a =initArray(size);
Arrays.sort(a);
Collections.sort(Arrays.asList(a));
long starttime =System.currentTimeMillis();
TreeSet set =new TreeSet();
set.addAll(Arrays.asList(a));
a = set.toArray(new Integer[0]);
System.out.println("耗时:"+(System.currentTimeMillis()-starttime)+"ms");
printArray(a);
}
private static Integer[] initArray(int size) {
Integer[] a =new Integer[size];
for (int i =0; i < size; i++) {
a[i] =random.nextInt(1000000000);
}
return a;
}
private static void printArray(Integer[] a) {
for (Integer temp : a) {
System.out.println(temp);
}
}
网友评论