java8 list取出重复值
@Test
public void test10(){
//根据device_code去重,取出重复值
List<Employee> emps =new ArrayList<>();
List<String> dupList = emps.stream().collect(Collectors.groupingBy(Employee::getName, Collectors.counting()))
.entrySet().stream().filter(e -> e.getValue() > 1)
.map(Map.Entry::getKey).collect(Collectors.toList());
System.out.println(dupList);
}
@Test
public void test11(){
//字符串取出重复值
List<String> list = new ArrayList<>();
List<String> repeatList = list.stream().collect(Collectors.groupingBy(e -> e, Collectors.counting()))
.entrySet().stream().filter(e -> e.getValue() > 1)
.map(Map.Entry::getKey).collect(Collectors.toList());
System.out.println(repeatList);
}
本文来自博客园,作者:格,转载请注明原文链接:https://www.cnblogs.com/yuangyuan/p/16449489.html