The classic solution is to wrap it using Collections.unmodifiableList().
For example:
List<Integer> sourceList;
List<Integer> readOnlyList = Collections.unmodifiableList(sourceList);
This will prevent everything except reading. If you want to prevent reading, do it private.
source
share