Swap the items in list - Java Quiz Question


Write a program to swap the items in list.

Input (Source Index, Destination Index, Input List) Output List(After Swap)
2
4
[MEC, EEE, CIVIL, ECE, CSE, IT]
[MEC, EEE, CSE, ECE, CIVIL, IT]
1
3
[MEC, EEE, CIVIL, ECE, CSE, IT]
[MEC, ECE , CSE, EEE, CIVIL, IT]
-1
3
[MEC, EEE, CIVIL, ECE, CSE, IT]
[MEC, EEE, CIVIL, ECE, CSE, IT]
2
-3
[MEC, EEE, CIVIL, ECE, CSE, IT]
[MEC, EEE, CIVIL, ECE, CSE, IT]
1
3
[]
[]
1
3
null
null


import java.util.*;
class SwapItemsInList
{
    public static void main(String s[])
    {
        ArrayList<String> list = new ArrayList<String>();
        list.add("Sachin Tendulkar");
        list.add("Sehwag");
        list.add("Yuvraj Singh");
        list.add("Dhoni");
        list.add("Gautam Gambhir");
        list.add("Suresh Raina");
        list.add("Rohit Sharma");
        list.add("Virat Kohli");
        int sourceIndex = 1;
        int destinationIndex = 3;
        System.out.println("The elements before swaping in list "+list);
        swapItems(sourceIndex, destinationIndex, list);
        System.out.println("The elements after swaping from source index "+sourceIndex+" to the destination index "+destinationIndex+" in list "+list);

    }


    public static void swapItems(int sourceIndex, int destinationIndex, List<String> list)
    {
    }

}