 <p>The solution that uses <code>Set</code> will probably be more readable, and easier to maintain - for example you avoid a whole class of problems when you modify your code like "what happens if I put a <code>false</code> value in the map - will it break my code?".</p> <p>As a side note, Java's <code>HashSet</code> is quite inefficient memory-wise and actually uses a <code>HashMap</code> under the covers. Still, in most cases it is code readability and maintainability that matters most and not implementation details like this.</p>