While passing a Collection as argument to a function, how can we make sure the function will not be able to modify it?
Anonymous
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.
Check out your Company Bowl for anonymous work chats.