-6

之前说 ArrayList 是空的。然后我在 ArrayList 的索引 1,000,000 处添加一个对象。

ArrayList 会创建 1,000,001 个指针还是只创建一个指针?

4

2 回答 2

5

将抛出 IndexOutOfBoundsException:

IndexOutOfBoundsException - 如果索引超出范围 (index < 0 || index > size())

http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html#add(int, E)

于 2013-10-28T09:19:32.913 回答
2

既然你问了,你甚至没有尝试过运行它。你会得到一个 IndexOutOfBounds 异常。

于 2013-10-28T09:19:45.757 回答