I have an Arraylist
, for example
ArrayList newObjectList = new ArrayList<>();
I want to use an object from
You can disable the remove
method using the Collections.unmodifiableList() construct:
List<Object> newObjectList = Collections.unmodifiableList(new ArrayList<Object>());
This will throw an UnsupportedOperationException
when trying to add or remove an object.
Use the method newObjectList.get(index)
instead
Documentation