- 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
IntStream toArray() method in Java
The toArray() method returns an array containing the elements of this stream.
Set the elements in the stream with the IntStream class of() method.
IntStream stream = IntStream.of(20, 40, 60, 70, 100, 120, 140);
Now, display an array with the elements of this stream using the toArray() method.
int[] myArr = stream.toArray();
The following is the syntax.
int[] toArray()
The following is an example to implement IntStream toArray() method in Java.
Example
import java.util.*; import java.util.stream.IntStream; public class Demo { public static void main(String[] args) { IntStream stream = IntStream.of(20, 40, 60, 70, 100, 120, 140); int[] myArr = stream.toArray(); System.out.println(Arrays.toString(myArr)); } }
Output
[20, 40, 60, 70, 100, 120, 140]
Advertisements