title: The frequency of items in HashMaps
body: <p>I have been trying to work out this code and I think there must be something I cannot see. Here are my class and its "add" function. The add is supposed to update the List and provide an information to the counter. Sadly, the HashMap doesn't respond whereas the List does. Any ideas? Thank you!</p>
  
  <pre><code>public class Basket {
  
  private List&lt;Product&gt; products;
  private HashMap&lt;Product, Integer&gt; counter;
  
  public Basket(){
      products = new LinkedList&lt;Product&gt;();
      counter = new HashMap&lt;Product, Integer&gt;();
  }
  
  public void add(Product product){
      products.add(product);
      for(Product key : counter.keySet()){
          if(product.getName() != key.getName()){
              counter.put(product, 1);
          }else{
              counter.put(product, counter.get(product) +1);
          }
      }
  }
  </code></pre>