swap method

void swap(
  1. int indexA,
  2. int indexB
)

Swaps the elements in the indices provided.

var list = [1, 2, 3, 4];
list.swap(0, 2); // [3, 2, 1, 4]

Implementation

void swap(int indexA, int indexB) {
  final temp = this[indexA];
  this[indexA] = this[indexB];
  this[indexB] = temp;
}