title: Implement ArrayList Class Remove Method Java
body: <p>I have to implement a custom built ArrayList Class. We can't use arrayCopy. I need to be able to remove a string from the array and then move all the elements to the left by one index. My attempt is below, please help.</p>
  
  <pre><code>/****************************************************************************
   * Removes the string at the specified index from the list,
   * if it is present and shifts the remaining elements left.
   *
   * @param  str value to remove from list
   * @return the value removed from the list
   * @throws IndexOutOfBoundsException if index is invalid
   */
      public String remove(int index){
          if (index &lt; 0 || index &gt;= this.myArray.length)
          {
              throw new IndexOutOfBoundsException("Index out of bounds.");
          }
          else {
          String removed = this.myArray[index];
          this.myArray[index] = null;
          String [] temp = new String[this.myArray.length-1];
          for(int i = 0; i&lt;this.myArray.length; i++){
          if (this.myArray[i] != null){
              temp[i] = this.myArray[i];
          }
      }
          return removed;
      }
      }       
  </code></pre>
  
  <p>I keep getting an <code>IndexOutOfBoundsException</code> at <code>temp[i] = this.myArray[i]</code>.</p>