The sample code given below will test your understanding of reversing the ArrayList object using the Collection Interface.
The sample code given below will test your understanding of reversing the ArrayList object using the Collection Interface.Given below the sample code :
import java.util.*;
public class reverseLIst {
public static void main(String[] args) {
ArrayList<String> mylist = new ArrayList<String>();
mylist.add("1");
mylist.add("2");
mylist.add("3");
System.out.println("Before reversing array list:"+mylist);
Collections.reverse(mylist);
System.out.println("After reversing array list:"+mylist);
}
}
What will be the output of the above code ?
1. Compilation error
2. No output
3. Before reversing array list:[1, 2, 3]
After reversing array list:[3, 2, 1]
4. Before reversing array list:[1, 2, 3]
After reversing array list:[1, 2, 3]
(3)