title: How to sort list of object by time in java
body: <p>What is the best way(FAST), how to sort list of my object by time (hour:minute:second);</p>
  
  <p>i have list of object:</p>
  
  <pre><code>ArrayList&lt;myObject&gt; test = new ArrayList&lt;&gt;();
  </code></pre>
  
  <p>i have class:</p>
  
  <pre><code>public class myObject{
  
  private final myTime actualTime;
  private final String name;
  
  public myObject(int hour, int minute, int second, String name){
       this.actualTime = new myTime(hour, minute, second);
       this.name = name;
  }
  
  private class myTime{
       private final hour, minute, second;
       public myTime(int hour, int minute, int second){
            this.hour=hour;
            this.minute = minute;
            this.second =second;
       }
  }
  
  }
  </code></pre>
  
  <p>Create test object:</p>
  
  <pre><code>test.add(new myObject(1, 0, 0, "Name1")); //1 hour, 0 minute, 0second...
  test.add(new myObject(9, 0, 0, "Name2"));
  test.add(new myObject(2, 0, 0, "Name3"));
  
  //now i want sort, but i dont know how?
  //i want print: Name2, Name3, Name1
  </code></pre>
  
  <p>I hope, you understand me, thank you for your advice.</p>
  
  <p>EDIT1:</p>
  
  <pre><code>   @Override
          public int compareTo(Object t) {
              hourTmp = ((myTime) t).getHour();
              if (this.getHour() &gt; hourTmp) {
                  return 1;
              } else {
                  return -1;
              }
          }
  </code></pre>