错误:
java.lang.IndexOutOfBoundsException: Index: 264, Size: 0
at java.util.ArrayList.rangeCheckForAdd(Unknown Source)
at java.util.ArrayList.add(Unknown Source)
我的代码:
import java.util.ArrayList
...
private static ArrayList<String[]> Arr = new ArrayList<String[]>();
...
Arr.add(264, new String[] {"title","description","icon"});
Arr.add(268, new String[] {"title2","description2","icon2"});
Arr.add(1222, new String[] {"title3","description3","icon3"});
我需要添加另一个带有自己的键
的字符串数组答案 0 :(得分:2)
除非列表至少已经很大,否则无法添加特定索引。
这一行:
Arr.add(264, new String[] {"title","description","icon"});
仅在列表中至少包含264个元素时才会起作用(如javadoc clearly states所示,如果您决定阅读它)。