title: What is the best way to sort an array of TIME in JAVA
body: <p>I have an array of time like this <code>Date[] arrival = new Date[n]</code> how to sort them in ascending order without using inbuilt Array.sort methods. </p>
  
  <pre><code>public static void sortArrival(Date[] arrival,int len) throws NullPointerException
  {
      for(int i=0;i&lt;len-1;i++)
      {
          for(int j=0;j&lt;len-1;j++)
          {
              if(arrival[j].before(arrival[j+1]))
              {
                  System.out.println("sorting dates..");
                  Date t = new Date();
                  t = arrival[j];
                  arrival[j] = arrival[j+1];
                  arrival[j+1]=t;
  
              }
          }
      }
  </code></pre>
  
  <p>However this method throws an null pointer exception! </p>