Java8 realizes that Map is sorted by value in one line

List<Map.Entry<Integer,Integer>>list = map.entrySet().stream()
      .sorted((entry1, entry2) -> entry1.getValue().compareTo(entry2.getValue()))
      .collect(Collectors.toList());

It is assumed that the value type is Integer, and other types are similar

 

Guess you like

Origin blog.csdn.net/qq_28411869/article/details/85792509