Home  >  Article  >  Java  >  How to use java Sorted

How to use java Sorted

PHPz
PHPzforward
2023-04-19 11:40:051669browse

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!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete