import java.util.ArrayList; public class Try { public static void main(String[] args) { // TODO Auto-generated method stub ArrayList<String> mylist = new ArrayList<>(); mylist.add(0, "A"); mylist.add(1, "A"); //注释掉,发现编译报错 //mylist.add(2, "NULL"); mylist.add(3, "B"); for(String i : mylist) { System.out.println(i); } } }