Collections.unmodifiableList(List <? extends T> list) has the following syntax.
public static <T> List <T> unmodifiableList(List <? extends T> list)
In the following code shows how to use Collections.unmodifiableList(List <? extends T> list) method.
import java.util.ArrayList; import java.util.Collections; import java.util.List; //from w w w . j ava 2s . c o m public class Main { public static void main(String[] args) { // create array list List<Character> list = new ArrayList<Character> (); // populate the list list.add('X'); list.add('Y'); System.out.println("Initial list: "+ list); // make the list unmodifiable List<Character> immutablelist = Collections.unmodifiableList(list); // try to modify the list immutablelist.add('Z'); } }
The code above generates the following result.