模仿sql查询集合对象过滤符合条件
程序员文章站
2022-07-12 14:13:50
...
List<User> list = new ArrayList<>();
User user1 = new User("张三",15,"男");
User user2 = new User("李四",22,"男");
User user3 = new User("王五",25,"男");
User user4 = new User("赵六",30,"男");
User user5 = new User("李世民",28,"男");
User user6 = new User("杨贵妃",18,"女");
User user7 = new User("貂蝉",16,"女");
list.add(user1);
list.add(user2);
list.add(user3);
list.add(user4);
list.add(user5);
list.add(user6);
list.add(user7);
List<User> collect = list.stream()
.filter(user -> "张三".equals(user.getName()))
.collect(Collectors.toList());
上一篇: C语言计算行列式以及代数余子式的函数
推荐阅读