
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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]
Advertisements