title: Inserting Character array into hashmap
body: <p>I have a wordcount program where I am reading from a character array, and inserting every word found (checking for blankspace) into a <code>HashMap&lt;Character[], Integer&gt;</code>, where the first parameter is the word, and the second parameter is the number of times it has been found.</p>
  
  <p>I do not use StringBuilder or Tokenizer because I am avoiding using Strings, as I am reading a 10gb file, and since Strings are immutable, it seems to cause memory issues.</p>
  
  <p>The following code seems to lag after reading only 20-30mb of the file. The problem seems to be that my key is a <code>Character[]</code>, so my get statement ALWAYS returns null. Not sure how to fix this without using Strings.</p>
  
  <p>Note - I build the word using an <code>ArrayList&lt;Character&gt;</code> - I then convert the array list into a <code>Character []</code>. I do this because inserting an ArrayList into a HashMap is quite problematic when check for equality. Also, this program is multithreaded, and each thread has its own hashmap.</p>
  
  <pre><code>public void run() {
          int i = 0;  Integer check;
          ArrayList&lt;Character&gt; charBuilder = new ArrayList&lt;Character&gt;();
          Character [] inserter;
          for (i = 0; i &lt; newbyte.length; i++) {
              if(newbyte[i] != ' ') {
                  charBuilder.add(newbyte[i]);
              }
              else { //delimiter found, insert word into local hashmap, clear builder
                     //convert to char [] first
                  inserter = charBuilder.toArray(new Character[charBuilder.size()]);
                  check = map.get(inserter);
                  if (check != null) { //already exists an entry
                      map.put(inserter, check + 1);
                  }
                  else {
                      map.put(inserter, 1);
                  }
                  charBuilder.clear();
                  inserter = null;
              }
          }
  </code></pre>
  
  <p>And the constructor</p>
  
  <pre><code>BigCountThread3(char[] newbyte, 
          HashMap&lt;Character[], Integer&gt; hashMap) { 
  </code></pre>