- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Program to convert Primitive Array to Stream in Java
To convert Primitive Array to Stream, you need to use the of() method.
Let’s say the following is our Primitive Array:
int[] myArr = new int[] { 20, 50, 70, 90, 100, 120, 150 };
Now, use the of() method to convert the primitive array to stream:
IntStream stream = IntStream.of(myArr);
The following is an example to convert primitive array to stream in Java:
Example
import java.util.stream.IntStream; import java.util.*; public class Main { public static void main(String[] args) { int[] myArr = new int[] { 20, 50, 70, 90, 100, 120, 150 }; System.out.println("The Primitive Array = "+Arrays.toString(myArr)); IntStream stream = IntStream.of(myArr); System.out.println("Primitive Array to Stream = " + Arrays.toString(stream.toArray())); } }
output
The Primitive Array = [20, 50, 70, 90, 100, 120, 150] Primitive Array to Stream = [20, 50, 70, 90, 100, 120, 150]
- Related Articles
- Java Program to convert Stream to typed array
- Program to convert Boxed Array to Stream in Java
- Program to convert Stream to an Array in Java
- Program to convert List to Stream in Java
- Java Program to convert String to short primitive
- Java Program to convert Stream to List
- Java Program to convert Java Float to Numeric Primitive Data Types
- How to convert Wrapper value array list into primitive array in Java?
- Program to convert a Map to a Stream in Java
- Java Program to convert Double to numeric primitive data types
- How to convert an input stream to byte array in java?
- How to Convert a Java 8 Stream to an Array?
- Program to convert a Set to Stream in Java using Generics
- Java Program to convert a Primitive Type Value to a String
- Convert Stream to Set in Java

Advertisements