Retrieve Object Value from Java Map using Map Key
<p>I'm trying to sync to user list by building a map that contains a username as a key and an user object as the value. Once the map has been built, I'm having difficulties retrieving the object values. Below is the code I'm using. </p>

<pre><code>private Map&lt;String, User&gt; map = new HashMap&lt;String, User&gt;();
</code></pre>

<p>I'm populating the map key and object as followed. </p>

<pre><code>        List&lt;User&gt; users = session.createCriteria(User.class).list();

        for(ApplicationUser user : users) {
            map.put(user.getUserName(), user);
        }
</code></pre>

<p>I'm trying to retrieve the data as followed, </p>

<pre><code>        List&lt;Person&gt; persons = session.createCriteria(Person.class).list();
        for (Person p : persons) {
            User user = map.containsKey(p.getUsername()) ? map.get(p.getUsername()) : new User();
            //Email is always null. 
            System.out.println(user.getEmail());
        }
</code></pre>

<p>Could someone help point me in the right direction on how to retrieve the object values from my map. Thanks</p>
