Java Streams - Stream of(T... values) example








Stream of(T... values) creates a stream from specified values.

Syntax

of has the following syntax.

@SafeVarargsstatic <T> Stream<T> of(T... values)

Example

The following example shows how to use of.

import java.util.stream.Stream;
/*w ww  .  j a  v  a 2s. c o  m*/
public class Main {
  public static void main(String[] args) {
    Stream<String> s = Stream.of("a","b");
    s.limit(10)
     .forEach(System.out::println); 

  }
}

The code above generates the following result.