What will be the result of execution of the following code?

Set<Integer> numbers = new LinkedHashSet<Integer>(Arrays.asList(1,2,3,4));
for(Integer i : numbers) {
  if( i % 2 == 0) numbers.remove(i);
Collections can't be modified in for-each loop. java.util.ConcurrentModificationException will be thrown at runtime.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Sign Up Now
or Subscribe for future quizzes