Stream of(T... values) example

Description

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;
/*from   ww  w  .j av a  2  s . com*/
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.





















Home »
  Java Streams »
    Reference »




Collectors
DoubleStream
DoubleStream.Builder
IntStream
IntStream.Builder
LongStream
LongStream.Builder
Stream
Stream.Builder