Java sort a list of object based on its different attributes : <p>I have a list with IP address, role and group. I want to firstly sort the the entire list with its group number. And based on the new list, for each group, I want to sort again by the role. Finally, based on the former sort, sort again by the IP address. I can't find a way to achieve my goal and struggle in it for a couple hours, please help, thank you in advance.</p>

<p>for example, the list is like: </p>

<pre><code>{
&lt;192.168.1.1, 1, "group 2"&gt;,
&lt;192.168.1.3, 1, "group 1"&gt;,    
&lt;192.168.1.7, 2, "group 1"&gt;,
&lt;192.168.1.25, 2, "group 1"&gt;,
&lt;192.168.1.1, 2, "group 2"&gt;
}
</code></pre>

<p>Ideally, after three sorts, the output should be something like:</p>

<pre><code>{
&lt;192.168.1.3, 1, "group 1"&gt;,
&lt;192.168.1.7, 2, "group 1"&gt;,
&lt;192.168.1.25, 2, "group 1"&gt;, 
&lt;192.168.1.1, 1, "group 2"&gt;,
&lt;192.168.1.1, 2, "group 2"&gt;
}
</code></pre>
