← Back to context

Comment by ptx

5 years ago

> Why are we using both int[] and ArrayList<Integer>? (Answer: because replacing the int[] with a second ArrayList<Integer> causes an out-of-bounds exception.)

Isn't it because one is pre-allocated with a known size of n and the other is grown dynamically?

> And what of thread safety?

Indeed. If he had written the prime number class like the earlier example, with public static methods creating a new instance for each call and all the other methods being private instance methods, this wouldn't be an issue.