Program to convert Boxed Array to Stream in Java Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report An array is a group of like-typed variables that are referred to by a common name. An array can contain primitives data types as well as objects of a class depending on the definition of the array. In case of primitives data types, the actual values are stored in contiguous memory locations. In case of objects of a class, the actual objects are stored in heap segment. A boxed array is an array which is defined in the form of an object, instead of the primitives. Example: int a = 4; Examples: Input: Array: [Geeks, forGeeks, A computer Portal] Output: Stream: [Geeks, forGeeks, A computer Portal] Input: Array: [1, 2, 3, 4, 5] Output: Stream: [1, 2, 3, 4, 5] Below are methods to convert Boxed Array to Stream in Java: Using Arrays.stream(): Algorithm: Get the Array to be converted. Convert the array into Stream using Arrays.stream() method by passing the array as the parameter. Return the formed Stream Program: Java // Java Program to convert // Array to Stream import java.util.*; import java.util.stream.*; class GFG { // Generic function to convert // an Array to Stream public static <T> Stream<T> convertArrayToStream(T array[]) { // Return the converted Stream return Arrays.stream(array); } public static void main(String args[]) { // Create an Array String array[] = { "Geeks", "forGeeks", "A Computer Portal" }; // Print the Array System.out.println("Array: " + Arrays.toString(array)); // convert the Array to Stream Stream<String> stream = convertArrayToStream(array); // Print the Stream System.out.println("Stream: " + Arrays.toString(stream.toArray())); } } Output: Array: [Geeks, forGeeks, A computer Portal] Stream: [Geeks, forGeeks, A computer Portal] Using Stream.of(): Stream.of() method creates a Stream directly with the values or collection passed as the parameter. Algorithm: Get the Array to be converted. Convert the array into Stream using Stream.of() method by passing the array as the parameter. Return the formed Stream Program: Java // Java Program to convert // Array to Stream import java.util.*; import java.util.stream.*; class GFG { // Generic function to convert // an Array to Stream public static <T> Stream<T> convertArrayToStream(T array[]) { // Return the converted Stream return Stream.of(array); } public static void main(String args[]) { // Create an Array String array[] = { "Geeks", "forGeeks", "A Computer Portal" }; // Print the Array System.out.println("Array: " + Arrays.toString(array)); // convert the Array to Stream Stream<String> stream = convertArrayToStream(array); // Print the Stream System.out.println("Stream: " + Arrays.toString(stream.toArray())); } } Output: Array: [Geeks, forGeeks, A computer Portal] Stream: [Geeks, forGeeks, A computer Portal] Using List.stream(): This is an indirect method in which the array is first converted into a List using Arrays.asList() method. Then the formed list is converted into a Stream using List.stream() method. Algorithm: Get the Array to be converted. Convert the array into List using Arrays.asList() method by passing the array as the parameter. Convert the formed List into Stream using List.stream() method. Return the formed Stream Program: Java // Java Program to convert // Array to Stream import java.util.*; import java.util.stream.*; class GFG { // Generic function to convert // an Array to Stream public static <T> Stream<T> convertArrayToStream(T array[]) { // Return the converted Stream return Arrays .asList(array) .stream(); } public static void main(String args[]) { // Create an Array String array[] = { "Geeks", "forGeeks", "A Computer Portal" }; // Print the Array System.out.println("Array: " + Arrays.toString(array)); // convert the Array to Stream Stream<String> stream = convertArrayToStream(array); // Print the Stream System.out.println("Stream: " + Arrays.toString(stream.toArray())); } } Output: Array: [Geeks, forGeeks, A computer Portal] Stream: [Geeks, forGeeks, A computer Portal] Create Quiz Comment R RishabhPrabhu Follow 0 Improve R RishabhPrabhu Follow 0 Improve Article Tags : Misc Java Java Programs Java - util package Java-Arrays java-stream java-list Java-Stream-programs Java-Array-Programs +5 More Explore Java BasicsIntroduction to Java3 min readJava Programming Basics9 min readJava Methods6 min readAccess Modifiers in Java4 min readArrays in Java7 min readJava Strings7 min readRegular Expressions in Java3 min readOOP & InterfacesClasses and Objects in Java5 min readAccess Modifiers in Java4 min readJava Constructors4 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages2 min readJava Interface7 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java4 min readIterator in Java4 min readJava Comparator Interface5 min readException HandlingJava Exception Handling6 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial3 min readSynchronization in Java7 min readFile Handling in Java4 min readJava Method References7 min readJava 8 Stream Tutorial7 min readJava Networking6 min readJDBC Tutorial5 min readJava Memory Management3 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers1 min readJava Programs - Java Programming Examples7 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions5 min readJava Quiz1 min readJava Project Ideas For Beginners and Advanced15+ min read Like