Make Collections readOnly
To make the Collection readOnly, we can use static methods of Collections class
Collections.unmodifiableCollection(Collection c)
Collections.unmodifiableMap(Map m)
Collections.unmodifiableList(List l)
Collections.unmodifiableSet(Set s)
If any add or remove operation will perform on the readOnly collection, it will throw UnSupportedOperationException.
No comments:
Post a Comment