- 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
LongStream toArray() method in Java
The toArray() method of the LongStream class returns an array containing the elements of this stream.
The syntax is as follows.
long[] toArray()
To use the LongStream class in Java, import the following package.
import java.util.stream.LongStream;
Create LongStream and add some elements.
LongStream longStream = LongStream.of(25000L, 28999L, 6767788L);
Create a Long array and use the toArray() method to return the elements of the stream as array elements.
long[] myArr = longStream.toArray();
The following is an example to implement LongStream toArray() method in Java.
Example
import java.util.*; import java.util.stream.LongStream; public class Demo { public static void main(String[] args) { LongStream longStream = LongStream.of(25000L, 28999L, 6767788L); long[] myArr = longStream.toArray(); System.out.println("The elements of the array: "+Arrays.toString(myArr)); } }
Output
The elements of the array: [25000, 28999, 6767788]
Advertisements