Vote Up 0 Vote Down

Test if a List is Unmodifable List

We would like to know how to test if a List is Unmodifable List.

answer


Vote Up 0 Vote Down
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
//from  ww w.javascrapbook.com/getanswer
public class Main {
  public static void main(String[] args) {
    List<Integer> list = new LinkedList<Integer>();
    list.add(1);
    List<Integer> unmodifiableList = Collections.unmodifiableList(list);
    System.out.println(unmodifiableList.getClass());
    if (unmodifiableList.getClass().getName().contains("UnmodifiableList"))
      System.out.println(true);
  }
}
flag | link

your answer

Who Are You?

Have an account already? Login before answering!