/** * Returns an iterator for the keys in the set. Remove is supported. Note that the same iterator * instance is returned each time this method is called. Use the {@link SetIterator} constructor * for nested or multithreaded iteration. */ public SetIterator<T> iterator() { if (iterator1 == null) { iterator1 = new SetIterator(this); iterator2 = new SetIterator(this); } if (!iterator1.valid) { iterator1.reset(); iterator1.valid = true; iterator2.valid = false; return iterator1; } iterator2.reset(); iterator2.valid = true; iterator1.valid = false; return iterator2; }