- sorted operation on stream returns a new stream whose items are sorted.
- There are two implementations, the first sorts the stream items in natural order and the second sorts the stream items using a comparator.
int stream three to one
Stream<Integer> threeToOne = Stream.of(3, 2, 1);
int stream two to one
Stream<Integer> twoToOne = Stream.of(2, 1);
Stream<Integer> oneToThree_sorted = threeToOne.sorted();
Stream<Integer> twoToOne_sorted_comparator = twoToOne.sorted((a,b) -> a.compareTo(b));