1z0-829 Exam QuestionsBrowse all questions from this exam

1z0-829 Exam - Question 24


Given the code fragment:

What is the result?

Show Answer
Correct Answer: A

Initially, when using `Collections.binarySearch(lst, "e3")` on the unsorted list `[

Discussion

2 comments
Sign in to comment
james2033Option: A
Feb 22, 2024

package q24; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class Q24 { public static void main(String[] args) { List lst = new ArrayList(); lst.add("e1"); lst.add("e3"); lst.add("e2"); int x1 = Collections.binarySearch(lst, "e3"); System.out.println(x1); Collections.sort(lst); int x2 = Collections.binarySearch(lst, "e3"); System.out.println(x2); Collections.reverse(lst); int x3 = Collections.binarySearch(lst, "e3"); System.out.println(x3); } } // Result: // 1 // 2 // -4

xplorerpjOption: A
Jun 25, 2024

A is correct answer