Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!

Idiom #357 Swap elements of list

Swap the elements at indices i, j in the list items

classes
items.exchange(i,j);
items[i], items[j] = items[j], items[i]
items.swap(i, j)
import static java.util.Collections.swap;
swap(items, i, j);
items[i], items[j] = items[j], items[i]
items[i], items[j] = items[j], items[i]
items.swap(i, j);

New implementation...
< >
programming-idioms.org