three steps of stream operations to create stream :
- Collection may be provided by a series of collection stream () or parallelStream (), i.e. a serial or parallel flow streams;
- () Gets array stream through a static method in stream Arrays;
- Stream class by the method of static ();
- Create an unlimited stream
package streamAPI; import lambda.Employee; import org.junit.Test; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.stream.Stream; public class TestStreamAPI1 { //创建Stream @Test public void test1() { //1.可以通过Collection系列集合提供的stream()或parallelStream(),即串行流或并行流 List<String> list = new ArrayList<>(); Stream<String> stream1 = list.stream(); //2.通过Arrays中的静态方法stream()获取数组流 Employee[] emps = new Employee[10]; Stream<Employee> stream2 = Arrays.stream(emps); //3.通过Stream类中的静态方法of() Stream<String> stream3 = Stream.of("aa", "bb", "cc"); //4.创建无限流 //迭代 Stream<Integer> stream4 = Stream.iterate(0, (x) -> x + 2); stream4.limit(10) .forEach(System.out::println); //生成 Stream.generate(() -> Math.random()) .limit(5).forEach(System.out::println); } }
See related function declaration: https://blog.csdn.net/qq_38358499/article/details/104636487
Java8 streamAPI new for (a)
Guess you like
Origin blog.csdn.net/qq_38358499/article/details/104641941
Recommended
Ranking