Here you can find the source of swap(List
public static <T> List<T> swap(List<T> list, int index1, int index2)
//package com.java2s; import java.util.List; public class Main { public static <T> List<T> swap(List<T> list, int index1, int index2) { list.set(index1, list.set(index2, list.get(index1))); return list; }/* w ww . j a va2s .co m*/ }