title: How to fix array index out of bounds error?
body: <p>The error that I am getting</p>
  
  <pre><code>Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 610
  at Fib.sorted(Fib.java:67)
  at Fib.main(Fib.java:17)
  </code></pre>
  
  <p>My code</p>
  
  <pre><code>public class Fib
  {
      public static void main(String args[]) 
      {
          System.out.println(Arrays.toString( fiblist) );
          System.out.println(Fib.add());
          System.out.println(Fib.square());
          System.out.println(Fib.reversal());
          System.out.println(Fib.sorted());
      }
  
       public static int fiblist[] = {1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765};
       public static int fiblen = fiblist.length;
  
       public Fib() 
       {
          // Do nothing
       }
  
       public static ArrayList&lt;Integer&gt; sorted()
       {
           ArrayList sorted = new ArrayList();
  
           for(int counter = 0; counter &lt; fiblist[4]; counter++ )
           {
               int temp1 = fiblist[counter];
               System.out.println("Elements stored " + temp1);
           }
           for(int counter = fiblist[14]; counter &lt; fiblist[19]; counter++)
           {
               int temp2 = fiblist[counter];
               System.out.println("Last Elements stored " + temp2);
           }
           return sorted;
      }
  }
  </code></pre>
  
  <p>I'm trying to store the last 5 elements of my array in temp 2.
  Then I will switch them. 
  Is there an easier way to do this?
  Switch the first five elements of an array with the last five?
  How would you switch them with a for loop?</p>