title: Using comparator in kotlin
body: <p>I'm new to kotlin, how to compare objects using <code>Collections</code></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>Collections.sort(list,myCustomComparator)</code></pre>
  </div>
  </div>
  </p>
  
  <p>How can we write a <code>MyCustomComparator</code> method in kotlin?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>private final Comparator&lt;CustomObject&gt; myCustomComparator = (a, b) -&gt; {
          if (a == null &amp;&amp; b == null) {
              return 0;
          } else if (a == null) {
              return -1;
          } else if (b == null) {
              return 1;
          } 
      };</code></pre>
  </div>
  </div>
  </p>