title: Group by field name in Java
body: <p>I'm trying to group Java objects by their field, i.e <em>Person.java</em></p>
  
  <pre><code>public class Person {
      String name;
      String surname;
      ....
  }
  </code></pre>
  
  <p>So if I have <em>n</em> Person objects, what would be the easiest way to get all people name "David" into a map like <code>Map&lt;String, List&lt;Person&gt;&gt; map;</code>?</p>
  
  <p>I found this on Google (but it doesn't compile), it seems to be the thing I'm looking for:
  <a href="http://www.anzaan.com/2010/06/grouping-objects-using-objects-property/" rel="noreferrer">http://www.anzaan.com/2010/06/grouping-objects-using-objects-property/</a></p>