title: How can I have a treeMap which is sorted by value keep being sorted when I change elements?
body: <p>I have a map of string keys and int values, I to sort them, and keep them sorted when I change values.
  I tried using a treemap for the sorted pairs and a normal map for the unsorted paris so I can use it in the comparator, but after a one value passes the other I get a null expection, this is the defenition:</p>
  
  <pre><code>public static TreeMap&lt;String, Long&gt; countryData;
  public static ValueComparator bvc;
  
  public static void setCountryData(HashMap&lt;String, Long&gt; map){
      bvc = new ValueComparator(map);
      countryData = new TreeMap&lt;String, Long&gt;(bvc);
      countryData.putAll(map);
      System.out.println(Arrays.toString(countyNames));
      System.out.println(countryData.values());
  
  
  }
  
  public static class ValueComparator implements Comparator&lt;String&gt; {
      Map&lt;String, Long&gt; base;
  
      public ValueComparator(Map&lt;String, Long&gt; base) {
          this.base = base;
      }
  
  
      public int compare(String a, String b) {
          if(base.get(a).equals(base.get(b))){
              return 0;
          }
          if (base.get(a) &gt; base.get(b)) {
              return -1;
          } else {
              return 1;
          }
      }
  }
  </code></pre>
  
  <p>this is how I change the values:</p>
  
  <pre><code>General.bvc.base.put(country, newValue);
  General.countryData.put(country, newValue);
  </code></pre>
  
  <p>after one value passes another and I try to acces it, I get a null, how can I Do this?</p>