| preferred AP College board partner for AP classes
AP Computer Science A/Unit 7: ArrayList
Start Practice TestPractice Test
About Exam
hard
Concurrent ArrayList Modification
< Prev
Next >

Consider the following code. What is the most likely issue to arise when multiple threads concurrently modify the unsynchronized ArrayList?

import java.util.ArrayList;

public class EndlessAdd {
    static ArrayList<Integer> list = new ArrayList<>();
    public static void main(String[] args) {
        for (int i = 0; i < 50; i++) {
            new Thread(() -> {
                for (int j = 0; j < 1000; j++) {
                    list.add(j);
                }
            }).start();
        }
    }
}
A

ConcurrentModificationException triggered by bulk additions

B

Deadlock due to too many threads acquiring locks simultaneously

C

Race conditions leading to data corruption and unpredictable list state

D

OutOfMemoryError due to rapid, unbounded growth of the ArrayList

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.

No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: [email protected]|Privacy Policy