数组、list排序

//数字排序 
   int[] intArray = new int[] {4, 1, 3, -23};
    Arrays.sort(intArray);
    输出: [-23, 1, 3, 4]
    
//字符串排序,先大写后小写
    String[] strArray = new String[] {"z", "a", "C"};
    Arrays.sort(strArray);
    输出: [C, a, z]
//严格按字母表顺序排序,也就是忽略大小写排序 Case-insensitive sort
    Arrays.sort(strArray, String.CASE_INSENSITIVE_ORDER);
    输出: [a, C, z]

//反向排序, Reverse-order sort
    Arrays.sort(strArray, Collections.reverseOrder());
   输出:[z, a, C]

//忽略大小写反向排序    Case-insensitive reverse-order sort
    Arrays.sort(strArray, String.CASE_INSENSITIVE_ORDER);
    Collections.reverse(Arrays.asList(strArray));
    输出: [z, C, a]

java List排序
    Collections.sort(menuSecondList, new Comparator<Record>() {
        @Override
        public int compare(Record o1, Record o2) {
        int i = o1.getInt("sort") - o2.getInt("sort") ;
        if(i == 0){
            return o1.getInt("sort")  - o2.getInt("sort");
        }
            return i;
        }
    });

 

posted @ 2019-06-25 17:49  某天清晨、  阅读(708)  评论(0编辑  收藏  举报