title: Group a list of objects by an attribute
body: <p>I need to group a list of objects (<code>Student</code>) using an attribute (<code>Location</code>) of the particular object. The code is like below:</p>
  <pre><code>public class Grouping {
      public static void main(String[] args) {
  
          List&lt;Student&gt; studlist = new ArrayList&lt;Student&gt;();
          studlist.add(new Student(&quot;1726&quot;, &quot;John&quot;, &quot;New York&quot;));
          studlist.add(new Student(&quot;4321&quot;, &quot;Max&quot;, &quot;California&quot;));
          studlist.add(new Student(&quot;2234&quot;, &quot;Andrew&quot;, &quot;Los Angeles&quot;));
          studlist.add(new Student(&quot;5223&quot;, &quot;Michael&quot;, &quot;New York&quot;));
          studlist.add(new Student(&quot;7765&quot;, &quot;Sam&quot;, &quot;California&quot;));
          studlist.add(new Student(&quot;3442&quot;, &quot;Mark&quot;, &quot;New York&quot;));
  
      }
  }
  
  class Student {
      String stud_id;
      String stud_name;
      String stud_location;
  
      Student(String sid, String sname, String slocation) {
          this.stud_id = sid;
          this.stud_name = sname;
          this.stud_location = slocation;
      }
  }
  </code></pre>
  <p>Please suggest me a clean way to do it.</p>