package J20250724.demo02_function_program; import java.util.ArrayList; import java.util.stream.Stream; /** * @author WanJl * @version 1.0 * @title Demo05 * @description * @create 2025/7/24 */ public class Demo05 { public static void main(String[] args) { ArrayList manList=new ArrayList<>(); manList.add("周润发"); manList.add("周星驰"); manList.add("成龙"); manList.add("周杰伦"); manList.add("周杰"); manList.add("林俊杰"); ArrayList womanList=new ArrayList<>(); womanList.add("林青霞"); womanList.add("张曼玉"); womanList.add("王祖贤"); womanList.add("林心如"); womanList.add("蔡文姬"); womanList.add("张韶涵"); //男演员只要名字为3个字的前三人 Stream manStream = manList.stream().filter(s -> s.length() == 3).limit(3); //女演员只要姓林的,并且不要第1个 Stream womanStream = womanList.stream().filter(s -> s.startsWith("林")).skip(1); //把过滤后的男演员姓名和女演员姓名合并到一起 Stream actorStream = Stream.concat(manStream, womanStream); //把上一步操作后的元素作为构造方法的参数创建演员对象,遍历数据 actorStream.forEach(name->{ Actor actor=new Actor(name); System.out.println(actor); }); } }