- 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 sorted() method in Java
The sorted() method of the LongStream class in Java returns a stream with the elements of this stream in sorted order.
The syntax is as follows −
LongStream sorted()
To use the LongStream class in Java, import the following package −
import java.util.stream.LongStream;
Create a LongStream and add some elements −
LongStream longStream = LongStream.of(80L, 35L, 15L, 70L, 30L, 45L);
Now, sort the elements of the stream −
longStream.sorted()
The following is an example to implement LongStream sorted() method in Java −
Example
import java.util.stream.LongStream; public class Demo { public static void main(String[] args) { LongStream longStream = LongStream.of(80L, 35L, 15L, 70L, 30L, 45L); System.out.println("Sorted elements in the stream = "); longStream.sorted().forEach(System.out::println); } }
Output
Sorted elements in the stream = 15 30 35 45 70 80
Advertisements