title: Linear Probing on Java HashTable implementation
body: <p>So I have a HashTable implementation here that I wrote using only Arrays and had a little bit of help with the code. Unfortunately, I don't quite understand one of the lines someone added while running the "get" or "put" method. What exactly is happening in the while loop below? It is a method for linear probing correct? Also why is the loop checking the conditions it's checking? </p>
  
  <p>Specifically, </p>
  
  <pre><code>int hash = hashThis(key);
  
      while(data[hash] != AVAILABLE &amp;&amp; data[hash].key() != key) {
  
          hash = (hash + 1) % capacity;
      }
  </code></pre>
  
  <p>Here's the whole Java class below for full reference. </p>
  
  <pre><code>public class Hashtable2 {
  
  private Node[] data;
  private int capacity;
  private static final Node AVAILABLE = new Node("Available", null);
  
  public Hashtable2(int capacity) {
  
      this.capacity = capacity; 
      data = new Node[capacity];
      for(int i = 0; i &lt; data.length; i++) {
  
          data[i] = AVAILABLE;
      }
  }
  
  public int hashThis(String key) {
  
      return key.hashCode() % capacity; 
  }
  
  public Object get(String key) {
  
      int hash = hashThis(key);
  
      while(data[hash] != AVAILABLE &amp;&amp; data[hash].key() != key) {
  
          hash = (hash + 1) % capacity;
      }
      return data[hash].element();
  }
  
  public void put(String key, Object element) {
  
      if(key != null) {
          int hash = hashThis(key);
          while(data[hash] != AVAILABLE &amp;&amp; data[hash].key() != key) {
  
              hash = (hash + 1) % capacity;
          }
  
          data[hash] = new Node(key, element);
  
      }
  
  }
  
  
  
  public String toString(){
  
      String s="&lt;";
  
      for (int i=0;i&lt;this.capacity;i++)
      {
          s+=data[i]+", ";    
  
      }
  
      s+="&gt;";
  
      return s;
      }
  </code></pre>
  
  <p>Thank you.</p>