IntStream boxed() method in Java


The boxed() method of the IntStream class returns a Stream consisting of the elements of this stream, each boxed to an Integer.

The syntax is as follows.

Stream<Integer> boxed()

At first, create an IntStream

IntStream intStream = IntStream.range(20, 30);

Now, use the boxed() method to return a Stream consisting of the elements of this stream, each boxed to an Integer.

Stream<Integer> s = intStream.boxed();

The following is an example to implement IntStream boxed() method in Java.

Example

 Live Demo

import java.util.*;
import java.util.stream.Stream;
import java.util.stream.IntStream;
public class Demo {
   public static void main(String[] args) {
      IntStream intStream = IntStream.range(20, 30);
      Stream<Integer> s = intStream.boxed();
      s.forEach(System.out::println);
   }
}

Output

20
21
22
23
24
25
26
27
28
29

Updated on: 30-Jul-2019

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements