title: Copying LinkedHashset content to new ArrayList?
body: <p>I've a listView that has some content initially. If the same content it gets, i removed the duplication through <code>linkedhashset</code>. Now, i want copy the <code>linkedhashset</code> contents i.e without duplication contents to new <code>ArrayList</code>. </p>
  
  <p>I tried to copy through </p>
  
  <pre><code>p.addAll(0,lhm);  // P is the instance of  ArrayList and lhm is linkedHashset instance
  </code></pre>
  
  <p>But, the <code>ArrayList</code> includes the duplication content too.</p>
  
  <p>Example : </p>
  
  <pre><code> ArrayList&lt;Price&gt; p = new ArrayList&lt;Price&gt;();
  
       p.add(new Price("Banana", 60));
       p.add(new Price("Apple", 80));
  
      LinkedHashSet&lt;Price&gt; lhm = new LinkedHashSet&lt;Price&gt;(p); 
      lhm.add(new Price("Banana", 20)); 
      lhm.add(new Price("Apple", 40));
      lhm.add(new Price("Orange", 30)); 
      for(Price pr:lhm)
      {
          System.out.println(pr);
      } 
      Price duplicate = new Price("Banana", 20);
      System.out.println("inserting duplicate object..."); 
      lhm.add(duplicate);
      lhm.add(new Price("Apple", 40));
      p.addAll(0,lhm);
      System.out.println("After insertion:"); 
      for(Price pr:lhm)
      {
          System.out.println(pr);
      }
  
      for (int i = 0; i &lt; p.size(); i++) {
  
          System.out.println(p.get(i).getItem() +"-" +p.get(i).getPrice());           
      }
  </code></pre>
  
  <p>Price.class</p>
  
  <pre><code>class Price
  {
      private String item; 
      private int price; 
      public Price(String itm, int pr)
      {
          this.item = itm; 
          this.price = pr; 
          }
      public int hashCode()
      { 
          System.out.println("In hashcode");
          int hashcode = 0; 
          hashcode = price;
          //System.out.println(hashcode);
  
          hashcode+= item.hashCode(); 
      //  System.out.println(hashcode);
  
          return hashcode;  
          }
  
      public boolean equals(Object obj)
      {
          System.out.println("In equals"); 
          if (obj instanceof Price) 
          {
              Price pp = (Price) obj; 
              return (pp.item.equals(this.item) &amp;&amp; pp.price == this.price); 
              }
          else 
          { 
              return false;
              }
          }
  
      public String getItem()
      {
          return item; 
      }
  
      public void setItem(String item) 
      { 
          this.item = item; 
          }
  
      public int getPrice() 
  
      {
          return price;
          }
      public void setPrice(int price) 
      {
          this.price = price; 
          }
      public String toString()
      {
          return "item: "+item+" price: "+price; 
          }
      }
  </code></pre>
  
  <p>Output : </p>
  
  <pre><code>In hashcode
  In hashcode
  In hashcode
  In hashcode
  In hashcode
  item: Banana price: 60
  item: Apple price: 80
  item: Banana price: 20
  item: Apple price: 40
  item: Orange price: 30
  inserting duplicate object...
  In hashcode
  In equals
  In hashcode
  In equals
  //iterating linkedhasset content
  
  After insertion:
  item: Banana price: 60
  item: Apple price: 80
  item: Banana price: 20
  item: Apple price: 40
  item: Orange price: 30
  
  // iterating ArrayList p content
  
  Banana-60
  Apple-80
  Banana-20
  Apple-40
  Orange-30
  Banana-60
  Apple-80 &lt;-- duplicate
  </code></pre>