title: Get index of element of an array java with hashCode
body: <p>I have a String array that contains a lot of words. I wish to get the index of a word contained in the array (-1 if it is not contained).</p>
  
  <p>I have first made a loop to search through all elements in the array while incrementing a variable and when I find it, I return the variable's value.</p>
  
  <p>However the array can be very very very big so searching through all elements is extremely slow. I have decided that before adding a new word in my string array, I would use <code>hashCode() % arrayLength</code> to get the index of where I should put it. Then, to get the index back, I would just reuse <code>hashCode() % arrayLength</code> to instantly know at what index it is. </p>
  
  <p>The problem is that sometimes there are "clashes", and two elements can have the same index in the array.</p>
  
  <p>Anyone has an idea how to deal with it? Or any other alternatives to get the index of an element faster? </p>