For the Collectors.groupingBy()
that returns Map<K,List<T>>
is it implied that the List<T>
is in order that the stream is evaluated?
I see no explicit description of the ordering of the list, whereas the concurrent version explicitly states no ordering. If it weren't ordered somehow, I'd expect it to be a Collection though, and I don't see what other ordering it could possibly be, other than order received.
I'm hoping it's guaranteed that the last value in each list is the last value received for that group.
The documentation for groupingBy()
says:
Implementation Requirements:
This produces a result similar to:
groupingBy(classifier, toList());
The documentation for toList()
says:
Returns:
a
Collector
which collects all the input elements into aList
, in encounter order
So, to answer your question, as long as your stream has a defined encounter order, you're guaranteed to get ordered lists.
EDIT: As @Holger points out, groupingBy()
would also have to respect encounter order to preserve toList()
's ordering constraint. The fact that it does is strongly implied in this note:
Implementation Note:
...If preservation of the order in which elements are presented to the downstream collector is not required, using
groupingByConcurrent(Function, Collector)
may offer better parallel performance.