title: java: Printing sorted arrayList is giving me IndexOutofBoundsException
body: <p>This is my Scheduler Class that sorts the arraylist. I made a custom compareTo method that returns an int value of 1, -1 or 0. </p>
  
  <pre><code>private ArrayList&lt;Event&gt; events = new ArrayList&lt;Event&gt;();
  
  
  public Scheduler(ArrayList&lt;Event&gt; events){
  
  
      for (int i=0; i&lt;events.size(); i++)
      {
          this.events.add(events.get(i));
  
      }
  
  } 
  
  public ArrayList&lt;Event&gt; getSchedule(){
      int i;
      int j;
      int N = events.size();
  
  
          for (i = 0; i &lt;=(N-1); i++)
      {
          for(j = 1; j &lt;= N;j++)
          {
  
      if(events.get(i).getEndTime().compareTo(events.get(j).getEndTime()) &gt; 0){
                  Collections.swap(events, i, j);
              }
          }   
      }
  
      return events;
  }
  </code></pre>
  
  <p>I call it later in my UI class </p>
  
  <p>Scheduler s = new Scheduler(events);</p>
  
  <pre><code>        System.out.println("Schedule:");
  
      for(int i = 0; i&lt;s.getSchedule().size(); i++){
          System.out.println(s.getSchedule().get(i)); 
          }
  </code></pre>
  
  <p>It's giving me an IndexOutofBoundError. Why is it giving me this error, and how can I fix it</p>