IntStream boxed() method in Java

Java 8Object Oriented ProgrammingProgramming

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
raja
Published on 27-Mar-2019 10:21:38
Advertisements