Java Streams - LongStream of(long... values) example








LongStream of(long... values) returns a sequential ordered stream whose elements are the specified values.

Syntax

of has the following syntax.

static LongStream of(long... values)

Example

The following example shows how to use of.

import java.util.stream.LongStream;

public class Main {
  public static void main(String[] args) {
    LongStream b = LongStream.of(1L, 2L, Long.MAX_VALUE, Long.MIN_VALUE);

    b.forEach(System.out::println);
  }
}

The code above generates the following result.