@Test public void test12(){ // 需要过滤的集合 List<Employee> first = Arrays.asList( new Employee(102, "李四", 79, 6666.66, Status.BUSY), new Employee(101, "张三", 18, 9999.99, Status.FREE), new Employee(103, "王五", 28, 3333.33, Status.VOCATION), new Employee(104, "赵六", 8, 7777.77, Status.BUSY), new Employee(105, "赵六", 8, 7777.77, Status.FREE), new Employee(106, "赵六", 8, 7777.77, Status.FREE), new Employee(107, "田七", 38, 5555.55, Status.BUSY) ); // 参照集合 List<Employee> second = Arrays.asList( new Employee(102, "李四", 79, 6666.66, Status.BUSY), new Employee(104, "赵六", 8, 7777.77, Status.FREE), new Employee(105, "田七", 38, 5555.55, Status.BUSY) ); List<Employee> lastResult = first.stream() .filter(add -> second.stream() .noneMatch(all -> Objects.equals(add.getId(), all.getId())&& Objects.equals(add.getAge(), all.getAge()) ) ).collect(Collectors.toList()); lastResult.forEach(System.out::println); //过滤条件: Objects.equals(add.getId(), all.getId()) }
标签:Status,BUSY,相同,list,getId,7777.77,Employee,new,java8 From: https://www.cnblogs.com/RedOrange/p/17091629.html