Java に関しては、Collections ユーティリティ クラスが役に立ちます。これらの操作を手動で行うのではなく、指定された API を使用することをお勧めします。特に、不変で変更不可能なメソッドに注目してください。
たとえば、不変に関しては次のとおりです。
<T> List<T>
emptyList()
Returns the empty list (immutable).
static
<K,V> Map<K,V>
emptyMap()
Returns the empty map (immutable).
static
<T> Set<T>
emptySet()
Returns the empty set (immutable).
変更不可の場合は次のとおりです。
static
<T> Collection<T>
unmodifiableCollection(Collection<? extends T> c)
Returns an unmodifiable view of the specified collection.
static
<T> List<T>
unmodifiableList(List<? extends T> list)
Returns an unmodifiable view of the specified list.
static
<K,V> Map<K,V>
unmodifiableMap(Map<? extends K,? extends V> m)
Returns an unmodifiable view of the specified map.
static
<T> Set<T>
unmodifiableSet(Set<? extends T> s)
Returns an unmodifiable view of the specified set.
static
<K,V> SortedMap<K,V>
unmodifiableSortedMap(SortedMap<K,? extends V> m)
Returns an unmodifiable view of the specified sorted map.
static
<T> SortedSet<T>
unmodifiableSortedSet(SortedSet<T> s)
他にもいくつかの戦略があり、その下に実装できますが、私はそこから始めます.