Here you can find the source of swapRemove(ArrayList
public static <E> E swapRemove(ArrayList<E> list, int index)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; public class Main { public static <E> E swapRemove(ArrayList<E> list, int index) { if (list.size() > 1) { list.set(index, list.get(list.size() - 1)); }/* w ww. ja v a 2 s. c om*/ return list.remove(list.size() - 1); } }