title: What to use - modulus or bitwise AND operator when creating an implementation of a Hashmap in Java?
body: <p>I have a university assignment in which we are to create our own HashMap implementation. In the assignment, when calculating the index of an entry to be placed in the array, it says to use the modulus operator:</p>
  <pre><code>int index = key.hashCode() % array.length;
  </code></pre>
  <p>But from everything I have gathered in my own research, the proper way to do it is using a bitwise AND operator:</p>
  <pre><code>int index = key.hashCode() &amp; (array.length - 1);
  </code></pre>
  <p>What are the advantages/disadvantages with these approaches? Does it matter or is one preferred? Thanks!</p>