要么我做错了,要么我不理解这种方法是如何工作的.
ArrayList<String> a = new ArrayList<String>();
a.ensureCapacity(200);
a.add(190,"test");
System.out.println(a.get(190).toString());
Run Code Online (Sandbox Code Playgroud)
我原本认为ensureCapacity会让我插入一个索引达到该值的记录.有没有不同的方法来做到这一点?
我在第三行得到一个IndexOutOfBounds错误.