title: LinkedHashSet remove duplicates object
body: <p>I have simple question to you, I have class Product that have fields like this:</p>
  
  <pre><code>private Integer id;
  private String category;
  private String symbol;
  private String desc;
  private Double price;
  private Integer quantity;
  </code></pre>
  
  <p>I want to remove duplicates item from LinkedHasSet based on ID, e.g Products that have same ID but diffrent quantity will be add to set, I want to remove (update) products with same ID, and it will by my unique id of object, how to do that?</p>
  
  <p>e.g
  Product: id=1, category=CCTV, symbol=TVC-DS, desc=Simple Camera, price=100.00, <strong>quantity=1</strong>
  Product: id=1, category=CCTV, symbol=TVC-DS, desc=Simple Camera, price=100.00, <strong>quantity=3</strong></p>
  
  <p>won't be added to set</p>
  
  <p>my code:</p>
  
  <pre><code>    public void setList(Set&lt;Product&gt; list) {
      if(list.isEmpty()) 
          this.list = list;
      else {
          this.list.addAll(list);
          Iterator&lt;Product&gt; it = this.list.iterator();
          for(Product p : list) {
              while(it.hasNext()) {
                  if(it.next().getId() != p.getId())
                      it.remove();
                      this.list.add(p);   
              }
          }
      }
  }
  </code></pre>