title: Java: Linear Probing Remove method
body: <p>i'm supposed to implement my own hash table through linear probing, however i'm having trouble with the remove function. it doesn't work correctly but i can't pinpoint the problem:</p>
  
  <pre><code>public void remove(Student s){
  
      if(s==null) throw new NullPointerException("Student is null");  /*check if student is null*/
  
      if (!contains(s)){                                               /*stop if students is not in table*/
          throw new NullPointerException();
      }
  
      int i = hashFunction(s);
      for(int j = 0; j&lt;array.length; j++){
          if(s.equals(array[j])){                                              /*found student*/
              array[j]=null;                                                  /*delete student*/
              break;
          }
      }
  
      for(int k= i; k&lt;array.length; k++){             /* find out if next element exists, if yes, move it to the gap of deleted student */
          if(!(array[k]==null)){
          int tempnext= hashFunction(array[k]);
  
              if(i &lt;= tempnext){
                  array[i]=array[tempnext];
              }
          }
      }   
  }
  </code></pre>
  
  <p>my debugger shows this as an output, so clearly my method has problems with gaps in the table:</p>
  
  <pre><code>Start:
  
  Array-Indices: [ 0] [ 1] [ 2] [ 3] [ 4] [ 5] [ 6] [ 7]
  Hash-Values:   [ 6] [ 1] [__] [ 6] [ 0] [ 5] [ 3] [ 0]
  Number:        [ 9] [ 6] [__] [ 2] [ 3] [ 4] [ 5] [ 8]
  
  Removing s6
  
  Array-Indices: [ 0] [ 1] [ 2] [ 3] [ 4] [ 5] [ 6] [ 7]
  Hash-Values:   [ 6] [ 6] [__] [ 6] [ 0] [ 5] [ 3] [ 0]
  Number:        [ 9] [ 2] [__] [ 2] [ 3] [ 4] [ 5] [ 8]
  
  Removing s5
  
  Array-Indices: [ 0] [ 1] [ 2] [ 3] [ 4] [ 5] [ 6] [ 7]
  Hash-Values:   [ 6] [ 6] [__] [ 5] [ 0] [ 5] [__] [ 0]
  Number:        [ 9] [ 2] [__] [ 4] [ 3] [ 4] [__] [ 8]
  </code></pre>
  
  <p>thanks in advance for any help!</p>