Note: "fruits" is Raw use of parameterized class 'List',
issue with existing code:
the "new Comparator" needs to be typecast as
new Comparator<String>(){}, to have a valid override of
public int compare(String m, String n) {}
after if, we typecast fruit list, below will work:
-fruits.sort((m, n) -> n.compareTo(m));
-fruits.sort((String d, String e) -> (e.compareTo(d)));
-fruits.sort((a, b) -> {
return b.compareTo(a);
});
there is no right answer
new Comparator() -> new Comparator<String>()
even if
List fruit is a raw type list
List.of("banana", "orange", "apple", "lemon");
is an Unmodifiable List
so there is
java.lang.UnsupportedOperationException
on fruits.sort()
If 1st line is List<String> -> A will be correct answer.
upvoted 1 times
...
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
aruni_mishra
7 months, 1 week agoASPushkin
9 months, 2 weeks agod7bb0b2
1 year agoSamps
1 year, 1 month agoduydn
1 year, 2 months ago