Junior — Middle
Is it possible to modify the contents of an immutable collection after its creation?
sobes.tech AI
Answer from AI
No, an immutable collection in Java cannot be modified after creation. Such collections are created with a fixed set of elements and do not support add, remove, or change operations.
For example, collections created with List.of(), Set.of(), or Collections.unmodifiableList() are immutable. Attempting to modify their contents will throw UnsupportedOperationException.
If you need to change the contents, you should use a mutable collection like ArrayList, or create a new collection based on the existing one with the desired modifications.