Java ArrayList 不为人知的陷阱,及add(int index, E element)和set(int index, E element)两个方法的说明 public class ArrayListTest { public static void main(String[] args) { List list = new ArrayList(2); System.out.println("lis
public class ArrayListTest { public static void main(String[] args) { Listlist = new ArrayList<>(2); System.out.println("list大小为:" + list.size()); list.add("12"); System.out.println("list大小为:" + list.size()); list.set(1,"sss"); list.add(1,"放在下标为1的位置"); list.add("22"); System.out.println("list大小为:" + list.size()); System.out.println(list.toString()); list.add(1,"放在下标为1的位置"); System.out.println("list大小为:" + list.size()); System.out.println(list.toString()); } }