swap

fun <T> swap(list: MutableList<T>, i: Int, j: Int)

Swaps the elements at the specified positions in the specified list. (If the specified positions are equal, invoking this method leaves the list unchanged.)

Since

1.4

Parameters

list

The list in which to swap elements.

i

the index of one element to be swapped.

j

the index of the other element to be swapped.

Throws

if either i or j is out of range (i < 0 || i >= list.size() || j < 0 || j >= list.size()).