【发布时间】:2014-02-08 22:21:01
【问题描述】:
我不明白为什么我收到错误 IndexOutOfBoundsException。使用 2 个移除器的代码工作正常,但是当我尝试添加第三个时,编译器甚至无法启动。
public class Solution
{
public static void main(String[] args) throws Exception
{
// 1. Here im making list
ArrayList list = new ArrayList();
//2. Putting values: «101», «102», «103», «104», «105».
list.add( 101); //0
list.add( 102);
list.add( 103); //2
list.add( 104);
list.add( 105); //4
// 3. removing first, middle and the last one. here is main problem, i cant add list.remove(4)
list.remove(0);
list.remove(2);
list.remove(4);
// 4. Using loop to get values on screen
for ( int i = 0; i < list.size(); i++){
System.out.println(list.get(i));
}
// 5. here im printing out size of arr
System.out.println(list.size());
}
}
【问题讨论】: