Question d’entretien chez Vaptech

While passing a Collection as argument to a function, how can we make sure the function will not be able to modify it?

Réponse à la question d'entretien

Utilisateur anonyme

5 sept. 2013

We can create a read-only collection using Collections.unmodifiableCollection(Collection c) method before passing it as argument, this will make sure that any operation to change the collection will throw UnsupportedOperationException.