Are you taking CLEP classes? Try clep.ai
| preferred AP College board partner for AP classes
AP Computer Science A/Unit 7: ArrayList
Start Practice TestPractice Test
About Exam
hard Solved by 1 students

Modifying ArrayList During Iteration

Mark
< Prev
Next >

What is the result of executing the following code segment?

import java.util.ArrayList;
public class Test {
    public static void main(String[] args) {
         ArrayList<Integer> list = new ArrayList<>();
         list.add(1);
         list.add(2);
         list.add(3);
         for(Integer i : list) {
             if(i == 2)
                list.remove(i);
         }
         System.out.println(list);
    }
}
A

It prints [1, 3]

B

A runtime error: ConcurrentModificationException

C

It prints [1, 2, 3]

D

Compilation Error

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question

Question Leaderboard

Not enough data yet to show leaderboard.

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy|