title: Comparing keys in HashMap and Values
body: <p>I have a HashMap as follows-</p>
  
  <pre><code>HashMap&lt;String, Integer&gt; BC = new HashMap&lt;String, Integer&gt;();
  </code></pre>
  
  <p>which stores as keys- "tokens/tages" and as values- "frequency of each tokens/tags".</p>
  
  <p>Example-</p>
  
  <pre><code>"the/at" 153
  "that/cs" 45
  "Ann/np" 3
  </code></pre>
  
  <p>I now parse through each key and check whether for same token say "the" whether it's associated with more than one tag and then take the largest of the two.</p>
  
  <p>Example-</p>
  
  <pre><code>"the/at" 153
  "the/det" 80
  </code></pre>
  
  <p>Then I take the key- <code>"the/at"</code> with value - <code>153</code>.</p>
  
  <p>The code that I have written to do so is as follows-</p>
  
  <pre><code>private HashMap&lt;String, Integer&gt; Unigram_Tagger = new HashMap&lt;String, Integer&gt;();
  
  for(String curr_key: BC.keySet())
          {
              for(String next_key: BC.keySet())
              {
                  if(curr_key.equals(next_key))
                      continue;
                  else
                  {
                      String[] split_key_curr_key = curr_key.split("/");
                      String[] split_key_next_key = next_key.split("/");
  
                      //out.println("CK- " + curr_key + ", NK- " + next_key);
  
                      if(split_key_curr_key[0].equals(split_key_next_key[0]))
                      {
                          int ck_v = 0, nk_v = 0;
                          ck_v = BC.get(curr_key);
                          nk_v = BC.get(next_key);
  
                          if(ck_v &gt; nk_v)
                              Unigram_Tagger.put(curr_key, BC.get(curr_key));
                          else
                              Unigram_Tagger.put(next_key, BC.get(next_key));
                      }
                  }
              }
          }
  </code></pre>
  
  <p>But this code is taking too long to compute since the original HashMap 'BC' has 68442 entries which comes approximately to its square = 4684307364 times (plus some more).</p>
  
  <p>My question is this- can I accomplish the same output using a more efficient method?</p>
  
  <p>Thanks!</p>