Comprehension

Report a typo

What will be the size of the onWriteArrayList?

public static void main(String[] args) throws InterruptedException {
    CopyOnWriteArrayList<Integer> onWriteArrayList = new CopyOnWriteArrayList<>();

    onWriteArrayList.add(-1);
    onWriteArrayList.add(-2);
    onWriteArrayList.add(-3);

    Thread writer = new Thread(() -> addNumbers(onWriteArrayList));
    writer.start();

    for (int i = -4; i > -10; i--) { // from the main thread
        onWriteArrayList.add(i);
    }

    writer.join(); // wait for writer thread to finish

    System.out.println(onWriteArrayList.size());
}

private static void addNumbers(CopyOnWriteArrayList<Integer> list) {
    for (int i = 0; i < 100_000; i++) {
        list.add(i);
    }
}
Select one option from the list
___

Create a free account to access the full topic