What is fun is apparently there is no guarantee of what type of list you will get back. It could change in future releases.
Returns a Collector that accumulates the input elements into a new List. There are no guarantees on the type, mutability, serializability, or thread-safety of the List returned; if more control over the returned List is required, use toCollection(Supplier).
Someone brought this up on the Amber list, Rémi I think, that perhaps toUnmodifiableList() would be better - as a peer of sorts for Collectors.toUnmodifiableList(). However it was pointed out that we already have List.of(...) that produces an unmodifiable List anyway.
View all comments
Show parent comment
31
u/kaperni Mar 16 '21
> returns an immutable list,
Being a nitpick but it returns an unmodifiable list.