Tuesday, October 27, 2015

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



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

No comments:

Post a Comment