title: Order list with objects based on attributes data in Java
body: <p>I need to order my List with 'Foo' objects based on a Enum value that Foo has as an attribute. I found 'Comparators', and I have used them before. But I always had some integer / double attribute, which is more clearer for me.</p>
  
  <p>Because this question might be vague, i'll make some spoonfed code so you guys can see what I mean / want. Thanks a bunch!</p>
  
  <pre><code>/* Enum class */
  public enum SomeEnum {
     CONSTANT_ALPHA, CONSTANT_BETA, CONSTANT_DELTA;
  }
  
  /* Class 'Foo', this is my Foo object */
  public class Foo {
      private SomeEnum enum; /* Every 'Foo' has a enum type */
  
      public Foo(SomeEnum enum){ 
          this.enum = enum; 
      }
  
      public SomeEnum getEnum(){ 
          return enun;
      }
  }
  
  /* Imagine this below is some controller class*/
  
   Foo alpha1 = new Foo(SomeEnum.CONSTANT_ALPHA);
   Foo beta1 = new Foo(SomeEnum.CONSTANT_BETA);
   Foo alpha2 = new Foo(SomeEnum.CONSTANT_ALPHA);
   Foo delta1 = new Foo(SomeEnum.CONSTANT_DELTA);
   Foo beta2 = new Foo(SomeEnum.CONSTANT_BETA);
  
   List&lt;Foo&gt; list = new ArrayList&lt;&gt;();
   list.add(alpha1);
   //list.add(beta1) etc etc (all those 5 Foos)
  
   Collections.sort(list, someComparatorIDontKnowHowToMake);
  
   System.out.println(list.toString()); /* Not sure how to correctly print a List&lt;&gt; object, but imagine I would print the contents of the list*/
  
   /* The result of the list should be: */
   /* alpha1, alpha2, beta1, beta2, delta1*/
  </code></pre>
  
  <p>In conclusion or TL;DR:</p>
  
  <p>I need to order the objects in the list based with the same Enum types. I do not need to have 'alpha' before 'delta' specifically. I just want that the Foo objects that have the same enum value are next to eachother in the List.</p>
  
  <p>If this didn't make sense, please do ask!</p>
  
  <p>Thanks.</p>