exam questions

Exam 1z0-819 All Questions

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

Exam 1z0-819 topic 1 question 124 discussion

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

Given the code fragment:



What is the result?

  • A. 2
  • B. -1
  • C. 1
  • D. -3
Show Suggested Answer Hide Answer
Suggested Answer: C 🗳️

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
ASPushkin
1 month, 3 weeks ago
Selected Answer: C
---- reverse order : Comparator<String> ms = (a,b) -> b.compareTo(a); b.compareTo(a) -1 b < a 1 b > a Comparator int compare (T o1, T o2) -1 01<02 Arrays.sort(towns, ms); returns [paris, oman, boston, bankok] System.out.println(Arrays.binarySearch(towns,"oman",ms)); returns 1 because ms comparator sorting is the same as before (Arrays.sort(towns, ms))
upvoted 1 times
...
d7bb0b2
6 months ago
Selected Answer: C
sort by comparator, and then the same comparator indiques to binary search how element is ordered. so print 1=> paris, oman, boston, bangkok
upvoted 1 times
...
Stavok
11 months, 3 weeks ago
Selected Answer: C
Arrays.sort method is then called with the towns array and the ms comparator, sorting the array in reverse order. The resulting sorted array is ["paris", "oman", "boston", "bangkok"]. The Arrays.binarySearch method is then called with the sorted towns array, the search key "oman", and the ms comparator. Since "oman" is found at index 1 in the sorted array, the method returns 1.
upvoted 1 times
Stavok
11 months, 3 weeks ago
However, there is a compilation error in the code because the Comparator interface is generic and requires type arguments. The correct way to define the ms comparator would be:Comparator<String> ms = (a, b) -> b.compareTo(a); which will print 1 after compilation
upvoted 1 times
...
Stavok
11 months, 3 weeks ago
However, there is a compilation error in the code because the Comparator interface is generic and requires type arguments. The correct way to define the ms comparator would be: Comparator<String> ms = (a, b) -> b.compareTo(a); which will print 1 after compilation
upvoted 1 times
...
...
KiraguJohn
1 year ago
C please not that Comparator<String> ms = (a,b)->b.compareTo(a) is not going to give you the same order as Comparator<String> ms = (a,b)->a.compareTo(b) one is descending and the other is ascending
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