Java ArrayList Swap swapRemove(ArrayList list, int index)

Here you can find the source of swapRemove(ArrayList list, int index)

Description

swap Remove

License

Open Source License

Declaration

public static <E> E swapRemove(ArrayList<E> list, int index) 

Method Source Code


//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);
    }
}

Related

  1. swap(ArrayList numbers, int i, int j)
  2. swap(ArrayList dataStrs, int i, int j)
  3. swap(ArrayList data, int i, int j)