Demo06.java 858 B

1234567891011121314151617181920212223242526272829
  1. package J20250724.demo02_function_program;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import java.util.stream.Collectors;
  5. /**
  6. * @author WanJl
  7. * @version 1.0
  8. * @title Demo06
  9. * @description
  10. * @create 2025/7/24
  11. */
  12. public class Demo06 {
  13. public static void main(String[] args) {
  14. List<Actor> actors=new ArrayList<>();
  15. actors.add(new Actor("周华健"));
  16. actors.add(new Actor("周润发"));
  17. actors.add(new Actor("周一位"));
  18. actors.add(new Actor("周节流"));
  19. System.out.println(actors);
  20. //把一个演员类的集合里的所有演员对象的姓名抽取出来,编程一个新的集合。
  21. List<String> stringList = actors.stream()
  22. .map(actor -> actor.getName())
  23. .collect(Collectors.toList());
  24. System.out.println(stringList);
  25. }
  26. }