Given:
import java.util.ArrayList; import java.util.Collection; import java.util.List; public class Main { public static void main(String[] args) { List<String> desk = new ArrayList<String>(); desk.add("pen"); desk.add("scissors"); desk.add("redStapler"); System.out.print(desk.indexOf("redStapler")); Collection.reverse(desk);/*from w w w .j a va 2s . com*/ System.out.print(" " + desk.indexOf("redStapler")); Collection.sort(desk); System.out.println(" " + desk.indexOf("redStapler")); } }
What is the result?
E is correct.
We had to throw at least one of these in here, sorry.
The reverse()
and sort()
methods are in the Collections class, not the Collection class-ouch.
Again, look for this kind of misdirection in the real exam! If the invocations had been Collections.
reverse(desk) and Collections.
sort(desk), the result would have been 2 0 1-remember, indexes are zero-based.