1Z0-829 Working with Arrays and Collections Practice Question
Given ArrayList<Integer> numbers = new ArrayList<>(List.of(1,2,3,4)); Which statement will insert element 10 at index 2?
⚠ Common exam trap
Many exam-takers confuse the `add(index, element)` method with `set(index, element)`, mistakenly thinking both insert, or they reverse the argument order, expecting `add(element, index)` as in some other languages.
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
✓
numbers.add(2,10);
The `ArrayList.add(int index, E element)` method inserts the specified element at the given index, shifting existing elements to the right. Here, `numbers.add(2,10)` inserts 10 at index 2, resulting in the list [1,2,10,3,4].
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
numbers.add(10,2);
Why it's wrong here
The add method expects index first, then element; this would attempt to add at index 10, causing IndexOutOfBoundsException.
- ✓
numbers.add(2,10);
Why this is correct
Inserts 10 at index 2, shifting subsequent elements to the right.
- ✗
numbers.set(2,10);
Why it's wrong here
set replaces the element at index 2, not insert.
- ✗
numbers.insert(2,10);
Why it's wrong here
No insert method exists in List or ArrayList.
Go deeper
Related to this question
About these practice questions
One of 513 original 1Z0-829 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. 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.