How to use boxed in IntStream?

Here is an example to explain how to use boxed in IntStream in java 8.

Syntax:

Modifier and Type         Method
Stream<Integer>           boxed()
package com.nourit.java8.Streams.IntStream;

import java.util.stream.IntStream;
import java.util.stream.Stream;

public class IntStreamBoxed {

  public static void main(String[] args) {
    System.out.println("---------- Boxed Example -----------------");
    IntStream intStream = IntStream.of(10, 11, 12, 13, 14, 15, 16);
    // Returns a Stream consisting of the elements of this stream, each boxed to an Integer.
    Stream<Integer> boxed = intStream.boxed();
    boxed.forEach(System.out::println);
    System.out.println("---------------------------------------");
  }
}

Output:

---------- Boxed Example -----------------
10
11
12
13
14
15
16
---------------------------------------

 

NOUR-IT

IT Training Center for Java and Web technology. If you enjoy and like our tutorials and believe in our mission, Please Subscribe us on Youtube and follow us on Twitter, or befriend us on Facebook or Google Plus.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

*