Java 8 Streams Java Java API
Interface:
java.util.stream.LongStream
Method:
LongStream sorted()
This stateful intermediate operation returns a stream consisting of the elements of this stream in sorted order.
Examples
package com.logicbig.example.longstream;
import java.util.stream.LongStream;
public class SortedExample {
public static void main(String... args) { LongStream.of(9, 11, 2, 17, 1, 5) .sorted() .forEach(System.out::println); } }
Output1 2 5 9 11 17
Parallel stream: package com.logicbig.example.longstream;
import java.util.stream.LongStream;
public class SortedExample2 {
public static void main(String... args) { LongStream.of(9, 11, 2, 17, 1, 5) .parallel() .sorted() .forEach(System.out::println); } }
Output9 11 1 5 2 17
|
|