标签:
Sorting an Array
1. 数字排序 int[] intArray = new int[] { 4, 1, 3, -23 };
Arrays.sort(intArray); 输出: [-23, 1, 3, 4]
2. 字符串排序,先大写后小写
String[] strArray = new String[] { "z", "a", "C" };
Arrays.sort(strArray);
输出: [C, a, z]
3. 严格按字母表顺序排序,也就是忽略大小写排序 Case-insensitive sort
Arrays.sort(strArray, String.CASE_INSENSITIVE_ORDER);
输出: [a, C, z]
4. 反向排序, Reverse-order sort
Arrays.sort(strArray, Collections.reverseOrder());
输出:[z, a, C]
5. 忽略大小写反向排序 Case-insensitive reverse-order sort
Arrays.sort(strArray, String.CASE_INSENSITIVE_ORDER);
Collections.reverse(Arrays.asList(strArray));
输出: [z, C, a]
标签:
原文地址:http://www.cnblogs.com/zjh225901/p/5448280.html