Enumeration<V> () { Enumeration<IntReference<V>> elementRefs = myMap.elements(); return new Enumeration<V>() { private V findNextRef() { while (elementRefs.hasMoreElements()) { IntReference<V> result = elementRefs.nextElement(); V v = result.get(); if (v != null) return v; } return null; } private V next = findNextRef(); @Override public boolean hasMoreElements() { return next != null; } @Override public V nextElement() { if (next == null) throw new NoSuchElementException(); V v = next; next = findNextRef(); return v; } }; }