title: How can I sort a collection of custom entities?
body: <p>I have a list of custom entities which I need to sort in this order: valueOne, valueTwo, and valueThree.</p>
  
  <p>Here is my code</p>
  
  <pre><code>public class AppRunner {
      public static void main(String[] args) {
  
          Detail d1 = new Detail("valueOne");
          Detail d2 = new Detail("valueTwo");
          Detail d3 = new Detail("valueFive");
          Detail d4 = new Detail("valueTen");
          Detail d5 = new Detail("valueOne");
          Detail d6 = new Detail("valueOne");
  
          List&lt;Detail&gt; details = new ArrayList&lt;Detail&gt;(Arrays.asList(d1, d2, d3, d4, d5, d6));
  
          Collections.sort(details);
          System.out.println(details);
      }
  }
  </code></pre>
  
  <p>My entity class</p>
  
  <pre><code>public class Detail implements Comparable&lt;Detail&gt; {
  
      private String value; // there are three options: valueOne, valueTwo, and some other value
  
      public Detail(String value) {
          this.value = value;
      }
  
      @Override
      public int compareTo(Detail detail) {
          String val = detail.getValue();
          if (val.equals(this.value) &amp;&amp; val.equals("valueOne")) {
              return 1;
          } else if (val.equals(this.value) &amp;&amp; val.equals("valueTwo")) {
              return -1;
          } else {
              return 0;
          }
      }
      // getter, setters, toString
  }
  </code></pre>
  
  <p>I think that need help with <code>compareTo</code> method. In the end I need to get list in this order:</p>
  
  <ol>
  <li>valueOne</li>
  <li>valueOne</li>
  <li>valueOne</li>
  <li>valueTwo</li>
  <li>valueFive</li>
  </ol>