HashSet extends AbstractSet<E> implements Set<E> { public Iterator<E> iterator() { return new HashSetIterator<E>() { public E next() { return nextEntry().key; } }; } HashSet();  HashSet(int capacity);  HashSet(int capacity, float loadFactor); boolean contains(Object key); boolean add(E key); boolean remove(Object key); Iterator<E> iterator(); int size(); 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()); }