If you have to implement it yourself, this will work:
void exchange(int i, int j) { ListIterator<int[]> it1 = matrix.listIterator(i), it2 = matrix.listIterator(j); int[] temp = it1.next(); it1.set(it2.next()); it2.set(temp); }
as it will be:
void exchange(int i, int j) { matrix.set(i, matrix.set(j, matrix.get(i))); }
The second is similar to the implementation of Collections.swap . The first is a bit more efficient for a long linked list.
finnw
source share