Concept
1. Sorted is an intermediate operation that returns a Stream in sorted order. If you do not enter a custom Comparator, the features will be arranged in natural order.
Usage Notes
2. After performing the Sorted operation, the order of the elements in stringCollection has not changed. Sorted only sorts the elements in the stream without changing the order of the elements in the original collection.
Example
stringCollection .stream() .sorted() .filter((s) -> s.startsWith("a")) .forEach(System.out::println); // "aaa1", "aaa2"
The above is the detailed content of How to use java Sorted. For more information, please follow other related articles on the PHP Chinese website!