public int fastUnorderedRemove ( @ DoNotSub final int index ) { checkIndex ( index ) ; final int value = elements [ index ] ; elements [ index ] = elements [ -- size ] ; return value ; }
Removes element at index but instead of copying all elements to the left it replaces the item in the slot with the last item in the list . This avoids the copy costs at the expense of preserving list order . If index is the last element it is just removed .