title: Sorting custom class array-list string using Collections.sort
body: <p>I am trying to sort my custom class array-list using Collections.sort  by declaring my own anonymous comparator. But the sort is not working as expected.</p>
  
  <p>My code is </p>
  
  <pre><code>Collections.sort(arrlstContacts, new Comparator&lt;Contacts&gt;() {
  
          public int compare(Contacts lhs, Contacts rhs) {
  
              int result = lhs.Name.compareTo(rhs.Name);
  
              if(result &gt; 0)
              {
                  return 1;
  
              }
              else if (result &lt; 0)
              {
                  return -1;
              }
              else
              {
                  return 0;
              }
          }
      });
  </code></pre>
  
  <p>The result is not in sorted order.</p>