title: Using hash maps in Java to find frequency of characters in a string
body: <p>I am trying to make an anagram program where I match all the keysets of a hash map with their values. But my code does not seem to count the occurrences of the character beyond the first.</p>
  
  <pre><code>String a="aabbcc";
  HashMap&lt;Character,Integer&gt; map= new HashMap&lt;Character, Integer&gt;();
  for(int i=0;i&lt;a.length();i++)
  {
      if(map.containsKey(a.charAt(i)))
      {
          int n= map.get(a.charAt(i))+1;
         map.put(a.charAt(i), n);
      }
  
      else
      {
          map.put(a.charAt(i), 0);
      }
  }
      System.out.println(map);
  </code></pre>
  
  <p>Output: </p>
  
  <pre><code>{a=1, b=1, c=1}
  </code></pre>