title: String IdentityHashMap vs HashMap performance
body: <p>Identity HashMap is special implementation in Java which compares the objects reference instead of <code>equals()</code> and also uses <code>identityHashCode()</code> instead of <code>hashCode()</code>. In addition, it uses <code>linear-probe hash table</code> instead of <code>Entry list</code>.  </p>
  
  <pre><code>Map&lt;String, String&gt; map = new HashMap&lt;&gt;(); 
  Map&lt;String, String&gt; iMap = new IdentityHashMap&lt;&gt;();
  </code></pre>
  
  <p>Does that mean for the <code>String</code> keys <code>IdentifyHashMap</code> will be usually faster if tune correctly ?</p>
  
  <p>See this example:</p>
  
  <pre><code>public class Dictionary {
  
      public static void main(String[] args) throws IOException {
          BufferedReader br = new BufferedReader(new FileReader("/usr/share/dict/words"));
  
          String line;
          ArrayList&lt;String&gt; list = new ArrayList&lt;String&gt;();
  
          while ((line = br.readLine()) != null) {
              list.add(line);
          }
          System.out.println("list.size() = " + list.size());
          Map&lt;String, Integer&gt; iMap = new IdentityHashMap&lt;&gt;(list.size());
          Map&lt;String, Integer&gt; hashMap = new HashMap&lt;&gt;(list.size());
  
          long iMapTime = 0, hashMapTime = 0;
  
          long time;
          for (int i = 0; i &lt; list.size(); i++) {
              time = System.currentTimeMillis();
              iMap.put(list.get(i), i);
              time = System.currentTimeMillis() - time;
              iMapTime += time;
              time = System.currentTimeMillis();
              hashMap.put(list.get(i), i);
              time = System.currentTimeMillis() - time;
              hashMapTime += time;
          }
  
          System.out.println("iMapTime = " + iMapTime + " hashMapTime = " + hashMapTime);
      }
  
  }
  </code></pre>
  
  <p>Tried very basic performance check. I am reading dictionary words (235K) &amp; pushing into the both maps. It prints:</p>
  
  <pre><code>list.size() = 235886
  iMapTime = 101 hashMapTime = 617 
  </code></pre>
  
  <p>I think this is very good improvment to ignore, unless I am doing something wrong here.</p>