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排序------------------