public static < T > boolean fastUnorderedRemove ( final ArrayList < T > list , final T e ) { for ( int i = 0 , size = list . size ( ) ; i < size ; i ++ ) { if ( e == list . get ( i ) ) { fastUnorderedRemove ( list , i , size - 1 ) ; return true ; } } return false ; }
Removes element but instead of copying all elements to the left moves into the same slot the last element . This avoids the copy costs but spoils the list order . If element is the last element then it is just removed .