Java Language Making a list unmodifiable


Example

The Collections class provides a way to make a list unmodifiable:

List<String> ls = new ArrayList<String>();
List<String> unmodifiableList = Collections.unmodifiableList(ls);

If you want an unmodifiable list with one item you can use:

List<String> unmodifiableList = Collections.singletonList("Only string in the list");