sort排序
通过Arrays.sort()进行排序(PS:sort方法是java.util.Arrays下的)
例:
int num [] = {3,5,7,9,2,1,4,6,8};
Arrays.sort(num);//调用sort方法进行排序
for(int n : num){//这是for循环的增强型---我的另一篇文章 for循环加强版
System.out.print(n + " ");
}
结果:
1 2 3 4 5 6 7 8 9
list排序
List<Integer> l = new ArraysList<Integer>();
l.add(2);
l.add(1);
l.add(3);
Conllections.sort(l);//使用collections的sort方法
for(int n : l){ //for循环的增强版
System.out.prrint(n + " ");
}