swap() function for arraylists.