【Java】创建Stream流对象

发布于:2021-12-05 17:41:21

创建Stream流对象

获取Stream流的方式:
1.通过单列集合的静态方法:strean()获取Stream流对象
2.通过Stream接口静态方法:of(数组)获取Stream流对象
3.通过Arrays工具类静态方法:stream(数组)获取Stream流对象


public class Demo {
public static void main(String[] args) {
Integer[] arr = {10,20,30,40,50};
Stream s1 = Arrays.stream(arr);
s1.forEach((Ingeter i)->{System.out.println(s);});

Stream s2 = Stream.of("aaa","bbb","ccc");
s2.forEach((String s)->{System.out.println(s);});

ArrayList list = new ArrayList();
list.add("张三");
list.add("李四");
list.add("王五");
Stream s3 = list.stream();
s3.forEach((String s));
}
}

相关推荐

最新更新

猜你喜欢