1. Through collections
The Collection interface of Java 8 has been extended to provide two methods for obtaining streams:
Return a sequential stream
default Stream\<E> stream()
Return a parallel stream
default Stream\<E> parallelStream()
2. The array stream can be obtained through the static method stream() of Arrays in Java 8
#Calling the static\3. Through the of() method of Stream
You can call the Stream class static method of() to create a stream by displaying the value. Can be used to receive any number of parameters
4. Create a stream
Iteration:
public static\<T> Stream\<T> iterate(final T seed, final UnaryOperator\<T> f)Generate:
public static\<T> Stream\<T> generate(Supplier\<T> s)
The above is the detailed content of What are the ways to create a Stream in Java?. For more information, please follow other related articles on the PHP Chinese website!