【发布时间】:2014-11-28 18:04:22
【问题描述】:
我有以下代码通过大小为 8 的 ArrayList。
public Tile[] getTiles(){
Tile[] tiles = {};
for(int i = 0; i < board.size(); i++){
try {
tiles[i] = board.get(i);
} catch(ArrayIndexOutOfBoundsException e){
System.out.println(i + " is out of bounds");
}
}
return tiles;
}
但是输出
0 is out of bounds
1 is out of bounds
2 is out of bounds
3 is out of bounds
4 is out of bounds
5 is out of bounds
6 is out of bounds
7 is out of bounds
8 is out of bounds
为什么ArrayList 中的所有元素都超出范围?
【问题讨论】:
标签: java arrays arraylist indexoutofboundsexception