This is a very basic example and I only used the existent methods.
import java.util.ArrayList;
public class A {
public static void main(String[] args) {
ArrayList<Integer> al = new ArrayList<Integer>();
// This should create an ArrayList of initial capacity 10
al.add(3,5); // Add 5 at index 3
al.add(7,2); // Add 2 at index 7
al.add(9,6); // Add 6 at index 9
System.out.println(al);
}
}
However, it throws the following exception:
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 3, Size: 0
I don't know why the exception is thrown. It look perfectly legal to me.