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

 
 

SCJP Module-9 Question-26
Posted on: July 19, 2010 at 12:00 AM
The Sample code given below will test your understanding about the Collection framework in Java.

Given below the sample code :

1 import java.util.*;
2 public class reverseLIst {
3 public static Iterator<String> reverse(List<String> mylist) {
4 Collections.reverse(mylist);
5 return mylist.iterator();
6 }
7
8 public static void main(String[] args) {
9 List<String> mylist = new ArrayList<String>();
10 mylist.add("1");
11 mylist.add("2");
12 mylist.add("3");
13 for (Object obj : reverse(mylist))
14 System.out.print(obj + ", ");
15 }
16 }

How can we correct the above code ?

1. No need of correction.

2. By replacing  " reverse(mylist)" with "Collections. reverse(mylist)" at line 13

3. By replacing "reverse(mylist)" with "mylist " at line 13.

4. By changing then 'reverse' class type.

Answer

(3)

Related Tags for SCJP Module-9 Question-26: