You declared an ArrayList , which has an initial capacity of 10 elements, but you have not added an element to this list, i.e. the list is empty. set will replace an existing element, but since there is no element in the list, an exception is thrown. You must add elements earlier using the add method.
Initial capacity means that the array that stores the list inside has a size of 10 at the beginning. As more items are added to the list, the size of this internal array may change.
source share