代码
List<Student> all = Student.getAll();
// 转换成数组 过滤所有的男性
Student[] students = all.stream().filter(s -> "男".equalsIgnoreCase(s.getSex()))
.toArray(Student[]::new);
System.out.println(Arrays.toString(students));
// 转换成集合 过滤所有的女性
List<Student> students1 = all.stream().filter(s -> "女".equals(s.getSex()))
.toList();
System.out.println(students1);
// 转换成map 过滤所有的女性,跳过第一个老师,取五个女生
Map<String, String> students2 = all.stream().filter(s -> "女".equals(s.getSex()))
.skip(1).limit(5)
.collect(Collectors.toMap(Student::getName, Student::getSex));
System.out.println(students2);
标签:Stream,java,Student,stream,System,filter,getSex,out
From: https://www.cnblogs.com/his365/p/17136089.html