Program to convert Boxed Array to Stream in Java


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]

Updated on: 25-Sep-2019

93 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements