Best way to implement compare method of Comparator in java?
<p>I have written a comparator which sorts by ascending order as below. which is working well.</p>

<pre><code>Collections.sort(resultList,new Comparator&lt;MyModelClass&gt;() {
            @Override
            public int compare(MyModelClass o1, MyModelClass o2) {
                Integer id1= o1.getId();
                Integer id2= o2.getId();
                if(id1 == null &amp;&amp; id2 == null) {
                    return 0;               
                }else if(id1 != null &amp;&amp; id2 == null) {
                    return -1;
                } else if (id1 == null &amp;&amp; id2 != null) {
                    return 1;
                } else {                
                    return id1.compareTo(id2);
                }
            }
        });
</code></pre>

<p>is it good to implement like this? Please help me?</p>

<p>Thanks!</p>
