1Z0-829 Working with Arrays and Collections Practice Question
Exhibit
Refer to the exhibit.
List<String> list = new ArrayList<>();
list.add("A");
list.add("B");
list.add("C");
list.add("A");
System.out.println(list.indexOf("A"));
System.out.println(list.lastIndexOf("A"));What is the output of the following code?
List<Integer> list = List.of(0, 1, 2, 3); System.out.println(list.indexOf(0) + " " + list.lastIndexOf(3));
⚠ Common exam trap
Candidates might mistakenly think that lastIndexOf(3) returns 2 due to off-by-one error, or confuse with other list methods like get().
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
✓
0 3
The list is [0, 1, 2, 3]. The indexOf(0) returns 0 because 0 is at index 0. The lastIndexOf(3) returns 3 because 3 is at index 3. The output is "0 3".
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
0 2
Why it's wrong here
This would be the output if lastIndexOf(3) returned 2, which is incorrect because 3 is at index 3.
- ✓
0 3
Why this is correct
Correct: indexOf(0) returns 0 and lastIndexOf(3) returns 3.
- ✗
1 2
Why it's wrong here
This would require indexOf(0) to return 1 and lastIndexOf(3) to return 2, both incorrect.
- ✗
1 3
Why it's wrong here
This would require indexOf(0) to return 1, which is incorrect.
Go deeper
Related to this question
About these practice questions
This 1Z0-829 question is part of Courseiva's 513-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This 1Z0-829 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-829 exam.