Person p1 = new Person("张三", new BigDecimal("23.0"));
Person p2 = new Person("王五", new BigDecimal("64.0"));
Person p3 = new Person("李四", new BigDecimal("75.0"));
Person p4 = new Person("王五", new BigDecimal("50.0"));
Person p5 = new Person("赵六", new BigDecimal("15.0"));
List<Person> pList = new ArrayList<>();
pList.add(p1);
pList.add(p2);
pList.add(p4);
pList.add(p3);
pList.add(p5);
System.out.println("未做过滤:" + pList);
List<Person> collect = pList.stream().filter(item -> item.getSalary().compareTo(new BigDecimal("50")) >= 0).collect(Collectors.toList());
System.out.println("做了过滤:" + collect);
打印结果:
未做过滤:[{name='张三', salary=23.0}, {name='王五', salary=64.0}, {name='王五', salary=50.0}, {name='李四', salary=75.0}, {name='赵六', salary=15.0}]
做了过滤:[{name='王五', salary=64.0}, {name='王五', salary=50.0}, {name='李四', salary=75.0}