Java Collectors.groupingBy()---is List ordered? - Stack Overflow
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.
Read full article from Java Collectors.groupingBy()---is List ordered? - Stack Overflow
No comments:
Post a Comment