exam questions

Exam 1z0-819 All Questions

View all questions & answers for the 1z0-819 exam

Exam 1z0-819 topic 1 question 135 discussion

Actual exam question from Oracle's 1z0-819
Question #: 135
Topic #: 1
[All 1z0-819 Questions]

Given:



Which statement will refactor line 2 to use a lambda expression?

  • A. fruits.sort((String d, String e) -> (e.compareTo(d);));
  • B. fruits.sort( o, p -> p.compareTo(o));
  • C. fruits.sort((String x, y) -> (return y.compareTo(x)));
  • D. fruits.sort((a, b) -> (return b.compareTo(a);));
Show Suggested Answer Hide Answer
Suggested Answer: D 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
aruni_mishra
7 months, 1 week ago
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); });
upvoted 1 times
...
ASPushkin
9 months, 2 weeks ago
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()
upvoted 2 times
...
d7bb0b2
1 year ago
Selected Answer: A
no answer correct list.of is inmutable. if that is corrected then: A and D are correct (correction sintax for ;)
upvoted 1 times
...
Samps
1 year, 1 month ago
A is the most correct but it gives a compilation error as a result of ';'
upvoted 1 times
...
duydn
1 year, 2 months ago
Selected Answer: A
If 1st line is List<String> -> A will be correct answer.
upvoted 1 times
...
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.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago