Home Tutorial Java Scjp Part9 SCJP Module-9 Question-22

 
 

SCJP Module-9 Question-22
Posted on: July 19, 2010 at 12:00 AM
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]

Answer

(3)

Related Tags for SCJP Module-9 Question-22:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.