问题在于ArrayList.remove()有两种方法,一种是Object,另一种是(int索引)。当您使用整数调用.remove时,它正在调用,
.remove(int)它会删除索引,而不是对象值。
为了回应评论,这里有更多信息。
该行在调用返回的索引处返回对象
int nr = numere.get(random.nextInt(numere.size())的 值
。下一行
numere.remove(...)尝试从ArrayList中删除该值。
您可以执行以下两种方法之一:
int idx = random.nextInt(numere.size());int nr = numere.get(idx);numere.remove(idx);
该
.remove(int)方法返回对象的remove的值,您也可以执行以下操作:
int idx = random.nextInt(numere.size());int nr = numere.remove(idx);
当然,如果需要,您可以将这两行合并为一条。


![从ArrayList中删除整数IndexOutOfBoundsException [重复] 从ArrayList中删除整数IndexOutOfBoundsException [重复]](http://www.mshxw.com/aiimages/31/455291.png)
