title: Use Collections.frequency with a List<SomeBeanType>
body: <p>I have a List of some bean type (Products) and I need to find what products from my list are repeated, lets say my bean Products contains getters and setters like these</p>
  
  <pre><code>public class Product {
   private int id;
   private String name;
   private BigDecimal cost;
   private int uniqueAssignedId;
  
   public Product(int id, String name, BigDecimal cost, int uniqueAssignedId) {
    this.id = id.....
   }
  
   public int getId() {
    return this.id;
   }
  
  //The rest of getters and setters.
  </code></pre>
  
  <p>I'm trying to put this list into a map to find repeated "id" values, but it isn't working as I expected, the problem is that my list is a list(sorry for the redundancy) of sold products so every sold product has a unique uniqueAssignedId therefore the Objects are always differents, assuming my list is filled as follows:  </p>
  
  <pre><code>listProducts.add(5, "Soda", 1.00, 1);
  listProducts.add(3,"Phone", 300.00, 2);
  listProducts.add(4, "Cofee", 5.00, 3);
  listProducts.add(5, "Soda", 1.00, 4);
  listProducts.add(4, "Cofee", 5.00, 5);
  listProducts.add(5, "Soda", 1.00, 6);
  </code></pre>
  
  <p>(I know I would have to create an object Product product = new Product() and fill it with the setters and then add the object to my list, but this is simpler)</p>
  
  <p>What I have tried as far:</p>
  
  <pre><code>Set&lt;Product&gt; uniqueId = new HashSet&lt;Product&gt;(listProducts);
          for (Product product : uniqueId) {
              System.out.println("The product with id "+product.getId+" was repeated: "
                      + Collections.frequency(listProducts, product.getId));
          }
  </code></pre>
  
  <p>But it always iterates 6 times instead of 3 times (3 is the number of differents products I sold). So How can I make the Hashset get only differents id? Should I use maps? Any clue will be appreciated.</p>