There are eight static methods in the Collections class that make a collection unmodifiable:
- Set<T> unmodifiableSet(Set<? extends T> set)
- List<T> unmodifiableList(List<? extends T> list)
- Map<K,V> unmodifiableMap(Map<? extends K, ? extends V> map)
- Collection<T> unmodifiableCollection (Collection<? extends T> collection)
- SortedSet<T> unmodifiableSortedSet(SortedSet<T> sortdedSet)
- SortedMap<K,V> unmodifiableSortedMap(SortedMap<K,? extends V> sortedMap),
- NavigableSet<T> unmodifiableNavigableSet(NavigableSet<T> navigableSet)
- NavigableMap<K,V> unmodifiableNavigableMap(NavigableMap<K,? extends V> navigableMap)
Here is an example of code that creates an unmodifiable list:
List<String> list = Arrays.asList ...