Question: Suppose we want to implement a Comparator so that it sorts the longest strings first. You may assume there are no null values. Which method
Suppose we want to implement a Comparator so that it sorts the longest strings first. You may assume there are no null values. Which method could implement such a comparator?

A. public int compare (String s1, String s2) { return s1.length() s2.length(); } B. public int compare (String s1, String s2) { return s2.length() s1.length(); } C. public int compare (Object obj1, Object obj2) { String s1 = (String) obj1; String s2 (String) obj2; return s1.length() s2.length(); } D. public int compare (Object obj1, Object obj2) { String s1 (String) obj1; String s2 = (String) obj2; return s2.length() } E. None of the above s1.length();
Step by Step Solution
3.33 Rating (153 Votes )
There are 3 Steps involved in it
The question is asking for a Comparator that will sort strings by length in descending order meaning ... View full answer
Get step-by-step solutions from verified subject matter experts
