-1
Map<String,Integer> map;
map.put("hey",1); 
map.put("k",0); 
map.put("thanks",12);

How can I iterate the map entries in order of the second operator (the numbers)? thanks

cylon
  • 735
  • 1
  • 11
  • 26
rhia
  • 1

1 Answers1

0
    Map<String, Integer> map = new HashMap<>();
    map.put("hey",1); map.put("k",0); map.put("thanks",12);
    map.entrySet().stream()
        .sorted((x, y) -> x.getValue() - y.getValue())
        .forEach(System.out::println);

resullt:

k=0
hey=1
thanks=12