title: Insertion Error Java ArrayIndex out of bounds
body: <p>Running this code:</p>
  
  <pre><code>public static int[] insertionSort(int[] array) {
      for (int j = 1; j &lt; array.length; j++) {
          int cur = array[j];
          int prev = j - 1;
          while ( (prev &gt; -1)  &amp;&amp; (array[prev] &gt; cur)) {
  
              array[cur] = array[prev];
              prev--;
          }
          array[prev + 1] = cur;
      }
      return array;
  
  }
  </code></pre>
  
  <p>I get an Indexoutofbounds error on array[cur] = array[prev];</p>
  
  <p>Here is my test case:</p>
  
  <pre><code>    int[] array = { 23, 5, 3, 5, 34, 2};
  </code></pre>
  
  <p>Why the error? The logic I think is good</p>