An other possible solution:
for(Object it : set.toArray()) { /* Create a copy */ Integer element = (Integer)it; if(element % 2 == 0) set.remove(element); } Or:
Integer[] copy = new Integer[set.size()]; set.toArray(copy); for(Integer element : copy) { if(element % 2 == 0) set.remove(element); }