Java Streams - LongStream boxed() example








LongStream boxed() returns a Stream boxed to a Long. This is an intermediate operation.

Syntax

boxed has the following syntax.

Stream<Long> boxed()

Example

The following example shows how to use boxed.

import java.util.stream.LongStream;
import java.util.stream.Stream;
//from  w w w .  j  av a  2  s  .  c o  m
public class Main {
  public static void main(String[] args) {
    LongStream b = LongStream.of(1L, 2L, Long.MAX_VALUE, Long.MIN_VALUE);
    Stream<Long> l = b.boxed();
    l.forEach(System.out::println); 
  }
}

The code above generates the following result.