title: Adding element in a list using hash table
body: <p>I want to insert an element in my list through hashing, when the element is already in the list, the list will not create duplicates. The element must be placed on the <strong>last position</strong> in my list. However, my code just insert in any position in my list. I do not know where I got wrong in my code.</p>
  <pre><code>boolean add(T key) {
  
          int position = getHash(key);
  
          if(table[position] == null) {
              table[position] = new Node(key);
          } else {
              Node element = table[position];
              while(element.next != null &amp;&amp; !element.key.equals(key))
                  element = element.next;
              if(element.key.equals(key))
                  return false;
              else
                  element.next = new Node(size);
          }
          size++;
          return true;
      }
  </code></pre>