title: Sort an ArrayList by primitive boolean type
body: <p>I want to sort my <code>ArrayList</code> using a boolean type. Basically i want to show entries with <code>true</code> first. Here is my code below:</p>
  
  <p><strong>Abc.java</strong></p>
  
  <pre><code>public class Abc {
   int id;
   bool isClickable;
  
   Abc(int i, boolean isCl){
      this.id = i;
      this.isClickable = iCl;
   }
   }
  </code></pre>
  
  <p><strong>Main.java</strong></p>
  
  <pre><code>List&lt;Abc&gt; abc = new ArrayList&lt;Abc&gt;();
  
  //add entries here
  
  //now sort them
  Collections.sort(abc, new Comparator&lt;Abc&gt;(){
          @Override
          public int compare(Abc abc1, Abc abc2){
  
              boolean b1 = abc1.isClickable;
              boolean b2 = abc2.isClickable;
  
              if (b1 == !b2){
                  return 1;
              }
              if (!b1 == b2){
                  return -1;
              }
              return 0;
          }
      });
  </code></pre>
  
  <p>Order before sorting:
       true 
       true 
       true 
       false 
       false 
       false 
       false 
       true 
       false 
       false </p>
  
  <p>Order after sorting:
  false 
   false 
   true 
   true 
   true 
   true 
   false 
   false 
   false 
   false</p>