@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); }
标签:Collectors,stream,重复,list,List,collect,java8 From: https://www.cnblogs.com/RedOrange/p/17091626.html