Monday, 25 April 2016

How to make a List read only ?


To make a List (ArrayList, Vector, LinkedList) read only, Use :

Collections.unmodifiableList(list)
It returns a new list.

If a user tries to perform add operation on the new list, it will throw :
UnSupportedOperationException

No comments:

Post a Comment

Note: only a member of this blog may post a comment.