Why is the sorted() method on Stream not named sort()?
Software Engineering Stack Exchange is a question and answer site for professionals, academics, and students working within the systems development life cycle. It only takes a minute to sign up.Sign up to join this community
According to the documentation, the
sorted() method is a stateful intermediate operation.
You can read more about what that means here:
Intermediate operations return a new stream. They are always lazy; executing an intermediate operation such as
filter()does not actually perform any filtering, but instead creates a new stream that, when traversed, contains the elements of the initial stream that match the given predicate.
sorted() describes the new stream created by the sorted() method, not the act of sorting.