Program to convert Boxed Array to Stream in Java

Java 8Object Oriented ProgrammingProgramming

A boxed array is an array which is defined in the form of an object, instead of the primitives.

Example

Following is the program to convert Boxed Array to Stream in Java −

import java.util.*;
import java.util.stream.*;
public class Demo {
   public static void main(String args[]) {
      String arr[] = { "Laptop", "Mobile", "Notebook", "Desktop" };
      System.out.println("Array = "+ Arrays.toString(arr));
      Stream<String>s = Stream.of(arr);
      System.out.println("Stream (array to stream) = "+ Arrays.toString(s.toArray()));
   }
}

Output

Array = [Laptop, Mobile, Notebook, Desktop]
Stream (array to stream) = [Laptop, Mobile, Notebook, Desktop]
raja
Published on 25-Sep-2019 08:09:30
Advertisements