Whats the most optimum way of swapping two elements in a List?
Location: http://www.jguru.com/faq/view.jsp?EID=483410 Created: Aug 24, 2001 Author: John Zukowski (http://www.jguru.com/guru/viewbio.jsp?EID=7) The 1.4 version of Collections has a swap() method to do this for you. However, for earlier version of Java, you can swap two elements w/o an intermediate variable with: list.set(index1, list.set(index2, list.get(index1))); This works because the set() method returns the original element.