Which statement is true about the following program?
// NEW RQ//from ww w . jav a 2s . c o m import java.util.ArrayList; import java.util.Arrays; 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("D")); list.add(new StringBuilder("C")); StringBuilder[] sbArray = list.toArray(new StringBuilder[0]); Collections.sort(list); Collections.sort(list, null); Collections.sort(list, Collections.reverseOrder()); System.out.println("List: " + list); Arrays.sort(sbArray); Arrays.sort(sbArray, null); Arrays.sort(sbArray, Collections.reverseOrder()); System.out.println("Array: " + Arrays.toString(sbArray)); } }
Select the one correct answer.
(d)
The class StringBuilder does not implement the Comparable interface.
The sort()
method (without the comparator) requires that the element type of the list is Comparable.
The program will not compile.