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);
}
System.out.println(numbers);
Explanation
Collections can't be modified in for-each loop. java.util.ConcurrentModificationException will be thrown at runtime.
Java
Java Quiz
Start Quiz

or Read more about Java Quiz

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback