To insert a value into an ArrayList at a specific index, use:
public void add(int index, E element)
This method will shift the subsequent list items. but you cannot guarantee that the list will remain sorted, since the new object you are inserting may be in the wrong position according to the sort order.
To replace an item at a specified position, use:
public E set(int index, E element)
This method replaces the element at the specified position in the list with the specified element and returns the element earlier at the specified position.
CloudyMarble Aug 16 2018-11-11T00: 00Z
source share