Here you can find the source of swapElements(List
public static <T> void swapElements(List<T> list, T element1, T element2)
//package com.java2s; //License from project: Open Source License import java.util.Collections; import java.util.List; public class Main { public static <T> void swapElements(List<T> list, T element1, T element2) { int index1 = list.indexOf(element1); int index2 = list.indexOf(element2); if (index1 == -1 || index1 == -1) { return; }//from w ww . j a va 2s. c om Collections.swap(list, index1, index2); } }