Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Whats the most optimum way of swapping two elements in a List?

elements list optimum swapping
0
Posted

Whats the most optimum way of swapping two elements in a List?

0

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.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123