标签:int color mat and class app bsp function 产生
public class Test { /* * Stream接口: * 实现类 * IntStream * DoubleStream * LongStream * * 一、创建Stream * 1、方式一:通过集合创建 * 集合对象.stream() * 2、方式二:通过数组工具类Arrays * Arrays.stream(数组对象) * 3、方式三:Stream接口的静态方法of方法,产生一个有限流 * Stream.of(...) * 4、方式四:Stream接口的静态方法 * (1)generate方法,产生无限流 * (2)Stream<T> iterate(T seed, UnaryOperator<T> f) */ public static void main(String[] args) { // test01(); // test02(); // test03(); // test04(); // test05(); test06(); } //通过集合创建 public static void test01() { List<Integer> list = Arrays.asList(1, 2, 3, 4, 5); //JDK1.8中,Collection系列集合增加了方法 Stream<Integer> stream = list.stream(); } //通过数组工具类Arrays public static void test02() { int[] arr = {1, 2, 3, 4, 5}; IntStream stream = Arrays.stream(arr); } //通过数组工具类Arrays public static void test03(){ String[] arr = {"hello","world"}; Stream<String> stream = Arrays.stream(arr); } //Stream接口的静态方法of方法,产生一个有限流 public static void test04(){ Stream<Integer> stream = Stream.of(1,2,3,4,5); stream.forEach(System.out::println); } //generate方法,产生无限流 public static void test05(){ Stream<Double> stream = Stream.generate(Math::random); stream.forEach(System.out::println); } // public static void test06(){ /* * Stream<T> iterate(T seed, UnaryOperator<T> f) * UnaryOperator接口,SAM接口,抽象方法: * * UnaryOperator<T> extends Function<T,T> * T apply(T t) */ Stream<Integer> stream = Stream.iterate(1, num -> num+=2); // stream = stream.limit(10); stream.forEach(System.out::println); } }
标签:int color mat and class app bsp function 产生
原文地址:https://www.cnblogs.com/hpdblogs/p/12491434.html