title: Missing value in a TreeMap after putAll()
body: <p>I have a HashMap that map character to an Integer. In order to sort it by value I wrote my comparator and I'm using TreeMap. But I am missing the value. I checked that for String "tree". My map 'chars' after for each loop looks like {r=1, t=1, e=2} and tree after putAll (two lines later) is {e=2, r=1}. What is happening to char 't'? Why is it missed? And how can I change it?</p>
  
  <pre><code>class ValueComparator implements Comparator&lt;Character&gt; {
  
  private Map&lt;Character, Integer&gt; map;
  
  public ValueComparator(Map&lt;Character, Integer&gt; map) {
      this.map = map;
  }
  
  public int compare(Character a, Character b) {
      return map.get(b).compareTo(map.get(a));
  }
  }
  
  public String frequencySort(String s) {
      if (s.length() &lt;= 1) return s;
  
      HashMap&lt;Character,Integer&gt; chars = new HashMap&lt;Character,Integer&gt;();
      for(Character c : s.toCharArray()){
          if (chars.containsKey(c)){
              chars.put(c,chars.get(c)+1);
  
          }
          else {
              chars.put(c,1);
          }  
      }
  
      TreeMap&lt;Character,Integer&gt; tree = new TreeMap&lt;Character,Integer&gt;(new ValueComparator(chars));
      tree.putAll(chars);
  
      /**
      * rest of the code
      **/
  
  }
  </code></pre>