title: Group objects in list by multiple parameters
body: <p>I have an entity that needs to be grouped several times by three of their properties, which enable a finer selection from left to right. Let's say I have this class:</p>
  
  <pre><code>public class Person {
      private String gender;
      private String state;
      private String age;
  }
  </code></pre>
  
  <p>Each property can hold the same value multiple times and I would like to group them accordingly. So that in the end I have the following data structure:</p>
  
  <pre><code>m --&gt; France  --&gt; 20 --&gt; Person1
                           Person2
                    21 --&gt; Person3
                           Person4
        Germany --&gt; 20 --&gt; Person5
                           ...
  </code></pre>
  
  <p>I hope you get the idea. Currently I use a deeply nested <code>Map</code> construction to achieve this: <code>Map&lt;String, Map&lt;String, Map&lt;String, Person&gt;&gt;&gt;</code></p>
  
  <p>Then I check for existing keys as in this answer: <a href="https://stackoverflow.com/questions/5385066/group-by-field-name-in-java#5385118">Group by field name in Java</a> for each  level of the Map and finally add my object to the "deepest" map.</p>
  
  <p>This should work although not tested yet, but is there any better way to do this? As in <em>better readable</em> or <em>faster execution</em></p>
  
  <p>Since it is only one <code>for</code> loop the execution time should be <em>O(n)</em> which is quite alright, but still, this does not seem to be the best solution.</p>