title: Alternating between two arraylists.
body: <p>I am having trouble getting this thing to run. I'm not sure if what I have so far is on the right track. I'm not quite sure where is is giving me an out of bounds error.</p>
  
  <p>Here are the instructions:</p>
  
  <p>Write a method called interleave that accepts two ArrayLists of integers a1 and a2 as parameters and inserts the elements of a2 into a1 at alternating indexes. If the lists are of unequal length, the remaining elements of the longer list are left at the end of a1. For example, if a1 stores [10, 20, 30] and a2 stores [4, 5, 6, 7, 8], the call of interleave(a1, a2); should change a1 to store [10, 4, 20, 5, 30, 6, 7, 8]. If a1 had stored [10, 20, 30, 40, 50] and a2 had stored [6, 7, 8], the call of interleave(a1, a2); would change a1 to store [10, 6, 20, 7, 30, 8, 40, 50].</p>
  
  <pre><code>private static void interleave(ArrayList&lt;Integer&gt; a1,
          ArrayList&lt;Integer&gt; a2) {
  
      int i = a1.size();
      int j = a2.size();
  
      if (i &lt; j) { // a1 is shorter than a2
          for (int k = 0; k &lt; a1.size(); k++) { // before k passes a1 size
              a1.add(k+1, a2.get(k));
          }
  
          for (int l = a1.size(); l &lt; a2.size(); l++) {
              a1.add(a1.size(), a2.get(l));
          }
  
      } else if (i &gt; j) { // a1 is longer than a2
          for (int k = 1; k &lt; a2.size(); k++) {
              a1.add(k+1, a2.get(k));
          }
  
      } else { // they are equal length
          for (int k = 1; k &lt; a2.size(); k++) {
              a1.add(k+1, a2.get(k));
          }
      }
  }
  </code></pre>