- 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
DoubleStream sorted() method in Java
The sorted() method of the DoubleStream class returns a stream consisting of the elements of this stream in sorted order.
The syntax is as follows
DoubleStream sorted()
To use the DoubleStream class in Java, import the following package
import java.util.stream.DoubleStream;
Create a DoubleStream and add some elements to the stream
DoubleStream doubleStream = DoubleStream.of(78.9, 90.4, 27.9, 20.6, 45.3, 18.5);
Now, sort the elements of the stream
doubleStream.sorted().
The following is an example to implement DoubleStream sorted() method in Java
Example
import java.util.*; import java.util.stream.DoubleStream; public class Demo { public static void main(String[] args) { DoubleStream doubleStream = DoubleStream.of(78.9, 90.4, 27.9, 20.6, 45.3, 18.5); System.out.println("Sorted stream..."); doubleStream.sorted().forEach(System.out::println); } }
Output
Sorted stream... 18.5 20.6 27.9 45.3 78.9 90.4
Advertisements