"", . , , .
, Stream.collect
.
Collector
:
A Collector , , , , . :
- (())
- (accumulator())
- (())
- (())
, toList()
, ArrayList::new
, List::add
List::addAll
, , , , .
Collectors.mapping
, , . , . mapper .
, Collectors.groupingBy
. , HashMap
. , Map.computeIfAbsent
, , , , . Map.merge
, , .
, , . ,
Map<Person.Sex, List<String>> namesByGender = new HashMap<>();
for(Person p: roster)
namesByGender.computeIfAbsent(p.getGender(), k -> new ArrayList()).add(p.getName());