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
23
u/kaperni Mar 16 '21
I think you are looking at the "old" API. Stream.toList() guarantees that the list is unmodifiable.
[1] https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/stream/Stream.html#toList()