Java Streams - Stream of(T t) example








Stream of(T t) creates a sequential Stream from a single element.

Syntax

of has the following syntax.

static <T> Stream<T> of(T t)

Example

The following example shows how to use of.

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

  }
}

The code above generates the following result.