Javatpoint Logo
Javatpoint Logo

How to make ArrayList Read Only?

The read-only means unmodifiable view of Collection in which we can not perform any operation which will change the collection through add(), remove() or set() method. We can obtain read-only collection from the existing collection by calling Collections.unmodifiableCollection() method.


    Exception in thread "main"java.lang.UnsupportedOperationException
at java.util.Collections$UnmodifiableCollection.add(
at collectionInterview.list.UnmodifiableArrayList.main(

Here we have converted the existing list fruitList to unmodifiable List. If we alter the "unmodifiableList", it will cause UnsupportedOperationException. We can still change the list with fruitList reference. like calling:

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA