Java Language Lists Making a list unmodifiable

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

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");


Got any Java Language Question?