I think it\'s a fairly simple question, but I can\'t figure out how to do this properly.
I\'ve got an empty arraylist:
ArrayList list =
I draw your attention to the ArrayList.add documentation, which says it throws IndexOutOfBoundsException - if the index is out of range (index < 0 || index > size())
IndexOutOfBoundsException
index < 0 || index > size()
Check the size() of your list before you call list.add(1, object1)
size()
list.add(1, object1)