Home  >  Article  >  Java  >  What should you pay attention to when using java's Sorted?

What should you pay attention to when using java's Sorted?

PHPz
PHPzforward
2023-04-30 10:28:13827browse

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.

Examples

stringCollection
    .stream()
    .sorted()
    .filter((s) -> s.startsWith("a"))
    .forEach(System.out::println);
// "aaa1", "aaa2"

What collection classes are there in Java

Collections in Java are mainly divided into four categories:

1, List List: ordered, repeatable;

2, Queue queue: ordered, repeatable;

3, Set collection: non-repeatable;

4, Map mapping: unordered, unique keys, non-unique values.

The above is the detailed content of What should you pay attention to when using java's 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