Is it a good idea to store data as keys in HashMap with empty/null values?
<p>I had originally written an <code>ArrayList</code> and stored unique values (usernames, i.e. <code>Strings</code>) in it. I later needed to use the <code>ArrayList</code> to search if a user existed in it. That's <code>O(n)</code> for the search.</p>

<p>My tech lead wanted me to change that to a <code>HashMap</code> and store the usernames as keys in the array and values as empty <code>Strings</code>.</p>

<p>So, in Java - </p>

<pre><code>hashmap.put("johndoe","");
</code></pre>

<p>I can see if this user exists later by running - </p>

<pre><code>hashmap.containsKey("johndoe"); 
</code></pre>

<p>This is <code>O(1)</code> right?</p>

<p>My lead said this was a more efficient way to do this and it made sense to me, but it just seemed a bit off to put null/empty  as values in the hashmap and store elements in it as keys.</p>

<p>My question is, is this a good approach? The efficiency beats <code>ArrayList#contains</code> or an array search in general. It works.
My worry is, I haven't seen anyone else do this after a search. I may be missing an obvious issue somewhere but I can't see it.</p>