title: HashMap<Key,List<Object>> from list of objects containing same property
body: <p>I have a List of objects.</p>
  
  <p>eg></p>
  
  <h2>Object 1</h2>
  
  <p>groupId=1
  name=name1</p>
  
  <h2>Object 2</h2>
  
  <p>groupId=1
  name=name2</p>
  
  <h2>Object 3</h2>
  
  <p>groupId=1
  name=name3</p>
  
  <h2>Object 4</h2>
  
  <p>groupId=2
  name=name4</p>
  
  <p>Multiple objects in the List have same value for <code>groupId</code>. I need to create Sub-Lists of objects with same <code>groupId</code>. How do I do this in Java.</p>
  
  <p>My Inital thought was to create a <code>HashMap&lt;Integer,List&lt;Object&gt;&gt;</code> but i am unsure about indefinite values of <code>groupIds</code> coming in , which in turn makes me unsure about  how to group objects with same <code>groupIds</code> together with <code>groupId</code> as the hashmap's key. </p>
  
  <p>If the groupId's were not to change or increase in the future i could have iterated over the original list and written a switch statement to create required arrays.</p>