import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;public class Demo {
public static void main(String[] args) {
Map<String, String> tempMap = new HashMap<>();
tempMap.put("aa", "1123");
tempMap.put("bb", "hello");
tempMap.put("cc", "hello");
tempMap.put("dd", "456");
tempMap.put("ee", "hello");
tempMap.put("ff", "1234555");
tempMap.put("gg", "456");
tempMap.put("hh", "aaaa");
tempMap.put("ii", "world");
tempMap.put("jj", "aaa");
List<String> valueList = tempMap.entrySet().stream().map(entry -> entry.getValue())
.collect(Collectors.groupingBy(s -> s, Collectors.counting()))
.entrySet().stream().filter(entry -> entry.getValue() > 1)
.map(entry -> entry.getKey()).collect(Collectors.toList());
Set<String> valueSet = tempMap.entrySet().stream().map(entry -> entry.getValue())
.collect(Collectors.groupingBy(s -> s, Collectors.counting()))
.entrySet().stream().filter(entry -> entry.getValue() > 1)
.map(entry -> entry.getKey()).collect(Collectors.toSet());
System.out.println(valueSet);
System.out.println(valueList);
}
}
取map里的重复value
最新推荐文章于 2022-03-22 12:12:25 发布