Table of contents




  • Collectors.tolist() -> Collects into a List

  • Collectors.toSet() -> Collects into a Set

  • Collectors.toMap(keyMapper, valueMapper) -> Collects into a Map
  • Collectors.groupingBy(Function) -> Groups elements by a key
  • Collectors.partitioningBy(Predicate) —> Partitions elements into two groups
    (true/false)
List<String> names = List.of("Alice", "Bob", "Charlie");
Map<Integer, List<String>> groupedByLength = names.stream()
                                                  .collect(Collectors.groupingBy(String: :length));