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.
(3)