- 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 sorted() method in Java
The sorted() method in Java IntStream class is used to return a stream consisting of the elements of this stream in sorted order.
The syntax is as follows
IntStream sorted()
The sorted() method returns the new stream. To work with the IntStream class, you need to import the following package
import java.util.stream.IntStream;
Create an IntStream and add some elements
IntStream intStream = IntStream.of(30, 50, 70, 120, 150, 200, 250, 300);
Now, to sort the above stream elements, use the sorted() method
intStream.sorted()
The following is an example to implement IntStream sorted() method in Java
Example
import java.util.stream.IntStream; public class Demo { public static void main(String[] args) { IntStream intStream = IntStream.of(30, 50, 70, 120, 150, 200, 250, 300); intStream.sorted().forEach(System.out::println); } }
Output
30 50 70 120 150 200 250 300
Advertisements