In Java, how can you make an ArrayList read-only (so that no one can add elements, edit, or delete elements) after initialization?
ArrayList
Pass the ArrayList into Collections.unmodifiableList(). It returns an unmodifiable view of the specified list. Only use this returned List, and never the original ArrayList.
Collections.unmodifiableList()
List
1.4m articles
1.4m replys
5 comments
56.9k users