KITFORMA · EDITORIAL ANSWER
Why does a list returned by Stream.toList reject add after a migration?
KitForma editorial guide. A terminal collection operation does not automatically promise a mutable result. Review the contract when replacing one stream terminal operation with another.
Step-by-step answer
stream.collect(Collectors.toCollection(ArrayList::new)), or construct a new ArrayList from the completed result. Keep Stream.toList when a nonmodifiable result is the intended boundary. Avoid depending on the runtime class of a collector implementation that does not promise a particular class.
Add a regression test that performs the actual downstream mutation rather than only comparing printed contents. Verify encounter order where the pipeline defines one. The mutable container does not make its elements immutable, and parallel upstream side effects remain a separate correctness issue.Sources and verification
Sources checked:
Scope: This editorial guide is based on the cited sources and tool behavior. A forum question or a query observed for our site does not establish market search volume, low competition, guaranteed rankings or inadequate answers elsewhere.
This editorial answer was prepared by KitForma with AI assistance. It is not presented as a real member question or an independent user review. Check the sources and the result with your own file; report corrections in the discussion.