Java stream().filter()筛选出符合条件的数据
1 单条件筛选筛选出性别为男的学生。List<Student> studentList = list.stream().filter(s->s.getGender().equals("1")).collect(Collectors.toList());2 多条件筛选筛选出性别为男并且身高为1米8以上的学生。List<Student> studentList = lis
·
1 单条件筛选
筛选出性别为男的学生。
List<Student> studentList = list.stream().filter(s->s.getGender().equals("1")).collect(Collectors.toList());
2 多条件筛选
筛选出性别为男并且身高为1米8以上的学生。
List<Student> studentList = list.stream().filter(s->s.getGender().equals("1")
&&s.getHeight()>=180).collect(Collectors.toList());
注:
stream()方法是jdk8才有的新特性,如果想使用stream()请保证jdk版本至少是jdk8及jdk8以上。
更多推荐
已为社区贡献37条内容
所有评论(0)