HashSet extends AbstractSet<E> implements Set<E> { @NotNull @Override public Iterator<E> iterator() { return new HashSetIterator<E>() { @Override public E next() { return nextEntry().key; } }; } HashSet();  HashSet(int capacity);  HashSet(int capacity, float loadFactor); @Override boolean contains(Object key); @Override boolean add(E key); @Override boolean remove(Object key); @NotNull @Override Iterator<E> iterator(); @Override int size(); @Override boolean isEmpty();  }
@Test public void iterator() { final HashSet<Integer> tested = new HashSet<Integer>(); final Set<Integer> set = new java.util.HashSet<Integer>(); for (int i = 0; i < 10000; ++i) { tested.add(i); set.add(i); } for (Integer key : tested) { Assert.assertTrue(set.remove(key)); } Assert.assertEquals(0, set.size()); }