public static < E > void swap ( List < E > list1 , List < E > list2 ) { int minLength = Math . min ( list1 . size ( ) , list2 . size ( ) ) ; for ( int i = 0 ; i < minLength ; i ++ ) { TrivialSwap . swap ( list1 , list2 , i ) ; } }
Helper method that swaps all the elements of the arrays . The run time of this method depends on the implementation of the lists since elements are removed and added in the lists . It also depends on the length of the shortest list .