--

I appreciate your comment to ensure why intelliJ suggests.

Yes, IntelliJ’s suggestion indicates that replacing Collectors.toList() with toList() would actually change the semantics.

the toList() method returns an unmodifiable list, which can lead to runtime exceptions if I try to modify it—like in my use case where I needed to remove elements from the list. That's why I opted for Collectors.toCollection(ArrayList::new), ensuring the list remains mutable.

Hope, my article clearly talk about this.

--

--

Responses (1)