java8 map过滤 map转字符串

Map<String,Long> map = new HashMap<>();
map.put("aaa",1L);
map.put("bbb",2L);
map.put("ccc",1L);

Map<String, Long> map2 = map.entrySet().stream().filter(e -> e.getValue().intValue() > 1)
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));

String str = map.entrySet().stream().filter(e -> e.getValue().intValue() > 1)
.map(e -> e.getKey())
.collect(Collectors.joining("、","{","}"));
posted @ 2023-10-23 15:52  可观可乐  阅读(118)  评论(0)    收藏  举报