Before java9 way to create read-only collection of
With static method Collections provided by operations:
- Create a read-only List
public static <T> List<T> unmodifiableList(List<? extends T> list)
- Create a read-only Set
public static <T> Set<T> unmodifiableSet(Set<? extends T> s)
- Create a read-only Map
public static <K,V> Map<K,V> unmodifiableMap(Map<? extends K, ? extends V> m)
java9 create a read-only collection after
Static methods use the interface provided by the byte of (), a series of overloads the method.