Collectors

Collectors end a stream by gathering its elements into a result: toList, toSet, joining, counting, groupingBy (groups into a Map), partitioningBy, summingInt, averagingDouble. A downstream collector can aggregate each group.

Example

Map<String, Long> parVille = clients.stream()
    .collect(Collectors.groupingBy(Client::ville, Collectors.counting()));

Related concepts

The whole glossary