15 February 2022


import java.util.ArrayList;
public class TestSwap
{

    public static <T> void swap(ArrayList<T> al, int j, int k)
    {
        if(j != k)
        {
            T tmp = al.get(j);
            al.set(j, al.get(k));
            al.set(k, tmp);
        }
    }
    public static void main(String[] args)
    {
        ArrayList<String> al = new ArrayList<>();
        al.add("a");
        al.add("b");
        System.out.println(al);
        swap(al, 0, 1);
        System.out.println(al);
    }
}