Java Streams - DoubleStream sorted() example








DoubleStream sorted() returns a stream consisting of the elements of this stream in sorted order.

Syntax

sorted has the following syntax.

DoubleStream sorted()

Example

The following example shows how to use sorted.

import java.util.stream.DoubleStream;
/*from w  w  w .ja va2  s.c o  m*/
public class Main {
  public static void main(String[] args) {
    DoubleStream d = DoubleStream.of(1.2,4.5,1.2,2.3);
    
    DoubleStream r = d.sorted();
     
    r.forEach(System.out::println);
  }
}

The code above generates the following result.