List<Integer> list= new ArrayList<>();
        list.add(3);
        list.add(2);
        list.add(5);
        list.add(2);
        Collections.sort(list, new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                if(o1==null||o2==null) {
                    return 0;            
                }
                //5->3->2->2  降序
                if(o1.intValue()<o2.intValue()) {
                    return 1;
                }else {
                    return -1; 
                }
                
            }
        });
        list.stream().forEach(item -> {
            System.out.println("item="+item);
        });

--------------------------将HashMap按value排序------------------
Collections.sort

相关文章:

  • 2022-12-23
  • 2021-10-11
  • 2022-12-23
  • 2021-10-09
  • 2021-10-24
  • 2022-12-23
  • 2021-08-07
猜你喜欢
  • 2021-06-14
  • 2022-12-23
  • 2021-09-02
  • 2022-12-23
  • 2022-12-23
  • 2021-10-29
  • 2021-10-24
相关资源
相似解决方案