Something went wrong

Report a typo

A code snippet below looks fine, but surprisingly a list size is less than 200_000. Take a look at the code snippet and explain what's wrong

class ChooseCollection {
    public static void main(String[] args) {
        List<Integer> numbers = new Vector<>();
        Thread thread = new Thread(() -> addNumbers(numbers));

        thread.start();
        addNumbers(numbers);

        System.out.println(numbers.size()); // < 200_000
    }

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

Create a free account to access the full topic