Pergunta de entrevista da empresa Vaptech

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

Resposta da entrevista

Sigiloso

5 de set. de 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.