Is the following code safe? Assume its single-threaded.
for(String s : set){
set.remove(s);
set.remove(randomElementFromSet());
}
I'm pretty sure this should be fine, but I want to double check that I run no risk of iterating over an element that has already been removed.
Also if possible please provide reference so I can look it up next time.