Grouping objects in a map
<p>This may be trivial, but I need to ensure I do it the correct way.</p>

<p>I have a person object which has property <code>country_id</code>. I need to group persons based upon <code>country_id</code> and then finally pack then into 1 Map object. The Map should have the key as the <code>country_id</code> and its value as List of person objects that belong to that <code>country_id.</code> </p>

<p>So the flow should be:</p>

<ul>
<li>Iterate through person objects</li>
<li>Find <code>country_id</code> and put in a list. e.g <code>person A(id=10)</code> in list_A</li>
<li>Similarly <code>person B(id-20)</code> in list_B</li>
<li>And then put them in HashMap? </li>
</ul>

<p>My final o/p should be <code>PersonMap(country_id-&lt;PersonList&gt;,country_id-&lt;PersonList&gt; )</code></p>

<p>Is this approach correct or is there a better approach?</p>
