Tuesday 3 November 2015

How to make Collections readOnly?

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

Related Posts Plugin for WordPress, Blogger...