Java中Collections和Arrays类
Collections
Collections是个java.util下的专用静态类,它包含有各种有关集合操作的静态方法。提供一系列静态方法实现对各种集合的搜索、排序、线程安全化等操作.
1
2
3
4
5
6
7
8
9
10
11public static void main(String[] args) {
List list = new ArrayList();
list.add(17);
list.add(11);
list.add(65);
list.add(36);
Collections.sort(list);
System.out.println(list);//[11, 17, 36, 65]
}
Arrays
Arrays是个java.util下的专用静态类,它包含有各种有关操作数组 ,提供搜索、排序、复制等静态方法。
1
2
3
4
5
6public static void main(String[] args) {
int[] array = new int[]{11, 4, 23, 16, 3, 1, 4};
Arrays.sort(array);
System.out.println(Arrays.toString(array));//[1, 3, 4, 4, 11, 16, 23]
}
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.