按第二个运算符(整数)的顺序迭代映射<字符串,整数> [JAVA]


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

如何按照第二个运算符(数字(的顺序迭代映射条目?谢谢

    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);

反驳:

k=0
hey=1
thanks=12

最新更新