Question 333 of 481
1Z0-811 binarySearch Practice Question
Exhibit
Refer to the exhibit.
public class Search {
public static int findIndex(int[] arr, int value) {
for (int i = 0; i < arr.length; i++) {
if (arr[i] == value) {
return i;
}
}
return -1;
}
public static void main(String[] args) {
int[] data = {5, 10, 15, 20};
int idx = findIndex(data, 15);
System.out.println(idx);
}
}What is the output?
⚠ Common exam trap
A common mistake is to confuse the return value of binarySearch with the actual value in the array. binarySearch returns the index of the search key, not the key itself.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
1
The code uses Arrays.binarySearch on a sorted array {1, 2, 3, 4, 5} to find the value 2. The method returns the index where the value is found, which is 1 (0-based). Since the code prints the return value of binarySearch directly, the output is 1.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
2
Why it's wrong here
Incorrect: 2 is the value searched for, but binarySearch returns the index, not the value.
- ✗
-1
Why it's wrong here
Incorrect: -1 would indicate the key is not found, but 2 is present at index 1.
- ✓
1
Why this is correct
Correct: binarySearch returns the index of 2, which is 1.
- ✗
3
Why it's wrong here
Incorrect: 3 is not the index of 2.
About these practice questions
Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →
Last reviewed: Jun 30, 2026
This 1Z0-811 practice question is part of Courseiva's free Oracle certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 1Z0-811 exam.
Question Discussion
Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.
Sign in to join the discussion.