Java Streams - IntStream boxed() example








IntStream boxed() returns a Stream boxed to an Integer. This is an intermediate operation.

Syntax

boxed has the following syntax.

Stream<Integer> boxed()

Example

The following example shows how to use boxed.

import java.util.stream.IntStream;
import java.util.stream.Stream;
/* w w w.  j  ava 2s .  c  o  m*/
public class Main {
  public static void main(String[] args) {
    IntStream i = IntStream.of(1,2,3,4,5,6,7);
    Stream<Integer> o =  i.boxed();
    
    o.forEach(System.out::println);
  }
}

The code above generates the following result.