Collectors Utility Class
About
stream.collect(Collectors.someCollectorMethod());Collecting into Lists, Sets, and Maps
Method
Description
List<String> list = List.of("Alice", "Bob");
List<String> unmodifiableList = list.stream().collect(Collectors.toList());
// Modifications via unmodifiableList will fail. But, if it's backed by a
// mutable list, changes to the original source can reflect in unmodifiableList
unmodifiableList.add("Charlie"); // Throws UnsupportedOperationExceptionList<String> immutableList = List.of("Alice", "Bob")
.stream()
.collect(Collectors.toUnmodifiableList());// Guaranteed to be immutable, regardless of the source.
// Modification attempts will always fail
immutableList.add("Charlie"); // Throws UnsupportedOperationExceptionAggregation and Summarization
Method
Description
Joining Strings
Method
Description
Grouping & Partitioning
Method
Description
Custom Reduction (reducing)
Method
Description
Last updated