Which statement is true about the following program?
import java.util.ArrayList; import java.util.Collections; import java.util.List; public class Main { public static void main(String[] args) { List<StringBuilder> list = new ArrayList<StringBuilder>(); list.add(new StringBuilder("B")); list.add(new StringBuilder("A")); list.add(new StringBuilder("C")); Collections.sort(list, Collections.reverseOrder()); System.out.println(list.subList(1,2)); }//from ww w . jav a 2 s .c om }
Select the one correct answer.
(c)
The class StringBuilder does not implement the Comparable interface.
The sort()
method that takes a comparator does not place any such requirements on the element type.
The program compiles, but throws a ClassCastException, as StringBuilder objects cannot be compared in reverse natural ordering.