title: calculating frequency of an element in hashmap
body: <p>I'm implementing a bag using a hashmap and I'm trying to calculate the frequency of an element in my hashmap and I keep getting one less than what it should be. </p>
  
  <p>this is my map </p>
  
  <pre><code>  private Map &lt;Integer, Integer&gt; map = new HashMap&lt;&gt;(); 
  </code></pre>
  
  <p>this is my add method </p>
  
  <pre><code> public void add(int element) {
   //containsKey 
   //checks if the element is already there 
   if (map.containsKey(element)){ 
      Integer numElt = map.get(element);
      map.put(element, (numElt+1)); //line where it should increment number of keys if the element is already there 
      count++; 
   }
  
   else { 
      map.put(element, 1); 
      count++; 
   }
  }
  </code></pre>
  
  <p>and my frequency </p>
  
  <pre><code>public int freq(int element) {
   Integer numE = map.get(element); 
   int k = Collections.frequency(map.values(), numE); 
   return k;
  </code></pre>
  
  <p>}</p>
  
  <p>if I write my test like so </p>
  
  <pre><code>Bag b = new Bag(): 
  b.add(4)
  b.add(5)
  b.add(5)
  
  assertTrue(2, b.freq(5)) 
  </code></pre>
  
  <p>should return 2 but it's returning 1. Not sure why that is and I'm sorry if it seems like an obvious error I'm new to bag implementation </p>