单项选择题
11. List list = // more code here
12. Collections.sort(list, new MyComparator());
Which code will sort this list in the opposite order of the sort in line 12?()
A. Collections.reverseSort(list, new MyComparator());
B. Collections.sort(list, new MyComparator()); list.reverse();
C. Collections.sort(list, new InverseComparator( new MyComparator()));
D. Collections.sort(list, Collections.reverseOrder( new MyComparator()));
相关考题
-
单项选择题
public class Drink implements Comparable { public String name; public int compareTo(Object o) { return 0; } } and: Drink one = new Drink(); Drink two = new Drink(); one.name= “Coffee”; two.name= “Tea”; TreeSet set = new TreeSet(); set.add(one); set.add(two); A programmer iterates over the TreeSet and prints the name of each Drink object. What is the result?()
A. Tea
B. Coffee
C. Coffee Tea
D. Compilation fails.
E. The code runs with no output.
F. An exception is thrown at runtime. -
多项选择题
1. public class Test { 2. public T findLarger(T x, T y) { 3. if(x.compareTo(y) > 0) { 4. return x; 5. } else { 6. return y; 7. } 8. } 9. } and: 22. Test t = new Test(); 23. // insert code here Which two will compile without errors when inserted at line 23?()
A. Object x = t.findLarger(123, “456”);
B. int x = t.findLarger(123, new Double(456));
C. int x = t.findLarger(123, new Integer(456));
D. int x = (int) t.findLarger(new Double(123), new Double(456)); -
单项选择题
11. public void addStrings(List list) { 12. list.add(”foo”); 13. list.add(”bar”); 14. } What must you change in this method to compile without warnings?()
A. add this code after line 11: list = (List
) list;
B. change lines 12 and 13 to: list.add(”foo”); list.add (”bar”);
C. change the method signature on line 11 to: public void addStrings(List< extends String> list) {
D. change the method signature on line 11 to: public void addStrings(List< super String> list) {
E. No changes are necessary. This method compiles without warnings.
