title: Different output of sorting code in Java 6 and Java 8
body: <p>I have a below code written for sorting my data .
  Output of this code is different in Java 6 and Java 8. Also the sequence in which objects are compared is reverse and I think this is causing change in final output.
  The sorting algorithm may not be correct but still can someone please explain  why this is working this way ?</p>
  <p>Please check attached code and output in Java 6 and Java 8.</p>
  <p><strong>Code</strong></p>
  <pre><code>package assignements;
  
  import java.util.ArrayList;
  import java.util.Collections;
  import java.util.Comparator;
  import java.util.List;
  
  class ComparableObject {
      private String id;
      private String name;
      private boolean hidden;
      private Integer order;
  
  
      ComparableObject() {
      }
  
      ComparableObject(String id, String name, boolean hidden, Integer columnOrder) {
          this.id = id;
          this.name = name;
          this.hidden = hidden;
          this.order = columnOrder;
      }
  
      public String getId() {
          return id;
      }
  
      public void setId(String id) {
          this.id = id;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public boolean isHidden() {
          return hidden;
      }
  
      public void setHidden(boolean hidden) {
          this.hidden = hidden;
      }
  
      public Integer getOrder() {
          return order;
      }
  
      public void setOrder(Integer order) {
          this.order = order;
      }
  }
  
  public class ComparatorPoc {
  
      public static void main(String[] args) {
          List&lt;ComparableObject&gt; list = new ArrayList&lt;ComparableObject&gt;();
          list.add(new ComparableObject(&quot;1547&quot;, &quot;id&quot;, false, 10));
          list.add(new ComparableObject(&quot;1548&quot;, &quot;name&quot;, true, 20));
          list.add(new ComparableObject(&quot;1592&quot;, &quot;customername&quot;, false, 30));
          list.add(new ComparableObject(&quot;1549&quot;, &quot;customername&quot;, true, 40));
          list.add(new ComparableObject(&quot;1551&quot;, &quot;OrderTo&quot;, false, 50));
          list.add(new ComparableObject(&quot;1553&quot;, &quot;PO&quot;, true, 60));
  
          Collections.sort(list, new Comparator&lt;ComparableObject&gt;() {
              @Override
              public int compare(ComparableObject o1, ComparableObject o2) {
                  System.out.println(o1.getName());
                  System.out.println(o2.getName());
                  System.out.println(&quot;****************&quot;);
                  boolean o1Hidden = o1.isHidden();
                  boolean o2Hidden = o2.isHidden();
                  if (o1Hidden &amp;&amp; o2Hidden)
                      return 0;
                  else if (o1Hidden)
                      return 1;
                  else
                      return -1;
              }
          });
  
          for (ComparableObject p : list) {
              System.out.println(&quot;Id=&quot; + p.getId() + &quot; Name=&quot; + p.getName() + &quot; Column Order=&quot; + p.getOrder() + &quot; IsHidden=&quot; + p.isHidden());
          }
      }
  }
  </code></pre>
  <p><strong>Java 6 Output</strong></p>
  <pre><code>id
  name
  ****************
  name
  customername
  ****************
  id
  customername
  ****************
  name
  customername
  ****************
  customername
  OrderTo
  ****************
  name
  OrderTo
  ****************
  customername
  OrderTo
  ****************
  customername
  PO
  ****************
  Id=1547 Name=id Column Order=10 IsHidden=false
  Id=1592 Name=customername Column Order=30 IsHidden=false
  Id=1551 Name=OrderTo Column Order=50 IsHidden=false
  Id=1548 Name=name Column Order=20 IsHidden=true
  Id=1549 Name=customername Column Order=40 IsHidden=true
  Id=1553 Name=PO Column Order=60 IsHidden=true
  </code></pre>
  <p><strong>Java 8 Output</strong></p>
  <pre><code>name
  id
  ****************
  customername
  name
  ****************
  customername
  name
  ****************
  customername
  id
  ****************
  customername
  id
  ****************
  customername
  name
  ****************
  OrderTo
  name
  ****************
  OrderTo
  id
  ****************
  OrderTo
  customername
  ****************
  PO
  id
  ****************
  PO
  customername
  ****************
  Id=1551 Name=OrderTo Column Order=50 IsHidden=false
  Id=1592 Name=customername Column Order=30 IsHidden=false
  Id=1547 Name=id Column Order=10 IsHidden=false
  Id=1548 Name=name Column Order=20 IsHidden=true
  Id=1549 Name=customername Column Order=40 IsHidden=true
  Id=1553 Name=PO Column Order=60 IsHidden=true
  </code></pre>