IntStream sorted() example

Description

IntStream sorted() returns a stream consisting of the elements of this stream in sorted order. This is a stateful intermediate operation.

Syntax

sorted has the following syntax.


IntStream sorted()

Example

The following example shows how to use sorted.


import java.util.stream.IntStream;
// w  ww  . j a  va 2  s  .  com
public class Main {
  public static void main(String[] args) {
    IntStream i = IntStream.of(6,5,7,1, 2, 3, 4);
    i.sorted()
     .forEach(System.out::println);
  }
}

The code above generates the following result.





















Home »
  Java Streams »
    Reference »




Collectors
DoubleStream
DoubleStream.Builder
IntStream
IntStream.Builder
LongStream
LongStream.Builder
Stream
Stream.Builder