HashMap相关操作 Collections排序
public class Demo {
public static void main(String[] args) {
HashMap<Integer, Integer> map = new HashMap<>();
map.put(1, 2);
map.put(2, 6);
map.put(3, 3);
List<Map.Entry<Integer, Integer>> list = new ArrayList<>(map.entrySet());
Collections.sort(list,(o1,o2) -> (o2.getValue().compareTo(o1.getValue())));
for(int i = 0; i < list.size(); i++){
System.out.println(list.get(i).getKey() + " " + list.get(i).getValue());
}
for(Integer key : map.keySet()){
System.out.println(key + " " + map.get(key));
}
}
}