The following part of the documentation for ArrayList does not seem correct to me:
The size, isEmpty, get, set, iterator, and listIterator operations run
in constant time.
Now set is defined as:
set(int index, E element)
Replaces the element at the specified position in this list with the specified element.
So this could be used to add an element in the middle of the ArrayList and cause the rest of the elements to shift.
But this is considered linear operation and not constant.
Am I wrong here? Or am I missunderstaning something?
It’s a set operation, not an add. It just replaces the i-th entry of the array.