unmodifiable collections

 

Collections provides six make-read-only methods:

 

unmodifiableCollection(Coll)

unmodifiableList(List)

unmodifiableCMap(Map)

unmodifiableSortedMap(SortedMap)

unmodifiableSet(Set)

unmodifiableSortedSet(SortedSet)           i.e.

 

Set set2 = Collections.unmodifiableSet( set1 );

 

■ Write attempts throw an UnsupportedOperationException

 

■ Note that this is the same for immutable collections, created by the nCopies(...) method.