java.util.stream.Stream#map 素颜马尾好姑娘i 2022-12-23 09:32 163阅读 0赞 ## java.util.stream.Stream\#map ## 遍历取值 * Teacher @Data @Builder public class Teacher { private String name; private Integer age; } * Solution public class Solution { public static void main(String[] args) { Teacher teacherA = new Teacher.TeacherBuilder().name("AA").build(); Teacher teacherB = new Teacher.TeacherBuilder().name("BB").build(); Teacher teacherC = new Teacher.TeacherBuilder().name("CC").build(); ArrayList<Teacher> teacherArrayList = Lists.newArrayList(); teacherArrayList.add(teacherA); teacherArrayList.add(teacherB); teacherArrayList.add(teacherC); List<String> collect = teacherArrayList.stream().map(Teacher::getName).collect(Collectors.toList()); System.out.println(JSON.toJSONString(collect)); } }
还没有评论,来说两句吧...