【Java】Stream流使用例子
package LearnJava22;
import java.util.ArrayList;
import java.util.stream.Stream;
public class StearmTest {
public static void main(String[] args) {
ArrayList<String> man = new ArrayList<>();
man.add("肖战");
man.add("王一博");
man.add("张艺兴");
man.add("蔡徐坤");
man.add("易烊千玺");
man.add("李易峰");
ArrayList<String> woman = new ArrayList<>();
woman.add("迪丽热巴");
woman.add("关晓彤");
woman.add("赵丽颖");
woman.add("刘诗诗");
woman.add("杨超越");
woman.add("杨幂");
// Stream<String> list1 = man.stream().limit(3).filter(s -> s.length() == 3);
//
// Stream<String> list2 =woman.stream().filter(s -> s.startsWith("杨")).skip(1);
//
// Stream<String> concat = Stream.concat(list1, list2);
//
// concat.map(Actor::new).forEach(p->{
// System.out.println(p.getName());
// });
// 简化
Stream.concat(man.stream().limit(3).filter(s -> s.length() == 3),
woman.stream().filter(s -> s.startsWith("杨")).skip(1))
.map(Actor::new).forEach(p -> System.out.println(p.getName()));
}
}
本文来自博客园,作者:木子欢儿,转载请注明原文链接:https://www.cnblogs.com/HGNET/p/16244074.html