Actually we can just clean the key with null value on the spot. An extra hashmap.remove while getting a key whose value is null wouldnt hurt.