swap method

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

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

Implementation

void swap(int indexA, int indexB) {
  final firstOld = get(indexA);
  final secondOld = set(indexB, firstOld);
  set(indexA, secondOld);
}