title: Shortcut for adding to List in a HashMap
body: <p>I often have a need to take a list of objects and group them into a Map based on a value contained in the object. Eg. take a list of Users and group by Country.</p>
  
  <p>My code for this usually looks like:</p>
  
  <pre><code>Map&lt;String, List&lt;User&gt;&gt; usersByCountry = new HashMap&lt;String, List&lt;User&gt;&gt;();
  for(User user : listOfUsers) {
      if(usersByCountry.containsKey(user.getCountry())) {
          //Add to existing list
          usersByCountry.get(user.getCountry()).add(user);
  
      } else {
          //Create new list
          List&lt;User&gt; users = new ArrayList&lt;User&gt;(1);
          users.add(user);
          usersByCountry.put(user.getCountry(), users);
      }
  }
  </code></pre>
  
  <p>However I can't help thinking that this is awkward and some guru has a better approach. The closest I can see so far is the <a href="http://google-collections.googlecode.com/svn/trunk/javadoc/index.html?com/google/common/collect/Multimap.html" rel="noreferrer">MultiMap from Google Collections</a>. </p>
  
  <p>Are there any standard approaches?</p>
  
  <p>Thanks!</p>