Skip to content
Sharp

Object-oriented programming · interview question

Why might you use Collections.unmodifiableList in your Java code?

Multiple choiceMediumchapter-3-curatedpremiumoopdefensive-copying
Choose one answer
Answer and explanation

Correct answer

A. To prevent modifications to the list from outside the class

Why

Collections.unmodifiableList creates a read-only view of the list that prevents any modifications. This is a useful strategy to protect the internal state of an object from external changes.

Test yourself on Object-oriented programming

A free test with instant, explained results. No account needed.

Start free test
All Object-oriented programming questions →