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

 
 

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

Advertisement

Related Tags for SCJP Module-9 Question-22:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: July 19, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com