title: Index 5 out of bounds for length 5 when trying to add an element to an array of objects
body: <pre><code>public static Groceries [] addGrocery(Groceries[] arr, String name, int price) {
          int arrayLength = Array.getLength(arr);
          System.out.println(arrayLength);
          Groceries[] newGrocery = new Groceries[arrayLength + 1];
          int arrayLength2 = Array.getLength(newGrocery);
          System.out.println(arrayLength2);
          int i;
          for(i = 0; i &lt; arrayLength; i++) {
              newGrocery[i] = arr[i];
              System.out.println(&quot;New item added&quot; + i);
          }
          newGrocery[i+1] = new Groceries(name, price);
          return newGrocery;
  
      }
  </code></pre>
  <p>I have this method where I input an array containing 4 objects and it creates a new array of objects copying the previous 4 objects and then adding one more to the array. But I keep getting this exception.</p>