Not clear on ArrayList documentation

The following piece of documentation for ArrayList doesn't seem right to me:

The operations size, isEmpty, get, set, iterator and listIterator are performed in constant time.

Now set to:

set (index int, element E)
          Replaces the element at the specified position in this list with the specified element.

Thus, this can be used to add an element in the middle of an ArrayList and make the rest of the elements move.
But this is considered linear, not permanent.

Am I wrong here? Or am I losing something?

+5
source share
6 answers

, . i- .

+9

ArrayList.set , . :

array[i] = something;

.

+5

, ArrayList .

, . ; .

+4

set (int index, E element) .

, (, )

+3

set . . .

+3

public Object set (int index, Object element) Replaces the element at the specified position in this list with the specified element (optional operation).

The method replaces the element by index and does not shift anything, the current element in the index will be returned to you and will no longer be in the list.

Thus, O (1)

+3
source

All Articles