wood burning stoves*
The moose likes Beginning Java and the fly likes How to remove duplicate element from List Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to remove duplicate element from List" Watch "How to remove duplicate element from List" New topic
Author

How to remove duplicate element from List

rushikesh kale
Ranch Hand

Joined: Jan 25, 2005
Posts: 41

Hi Freinds,

I want to remove duplicate element from my List.
I have following List:


which contains follwoing elements {2,4,5,6,3,5,2,3}

Now i want to remove common elements such as {2,3}
can you please tell me how can i do that
Amit M Tank
Ranch Hand

Joined: Mar 28, 2004
Posts: 257
Use a Set instead of a list


Amit Tank
Linked In
Guido Sautter
Ranch Hand

Joined: Dec 22, 2004
Posts: 142
Try adding the List elements to some duplicate free, order-preserving collection (a SortedSet, eg a LinkedHashSet), clear the List, and refill it from the set. Then, you have the elements in the List in the same order as before, but without the duplicates.
Bill Shirley
Ranch Hand

Joined: Nov 08, 2007
Posts: 457
Don't double post, please.
faq.javaranch.com/java/UseOneThreadPerQuestion


Bill Shirley - bshirley - frazerbilt.com
if (Posts < 30) you.read( JavaRanchFAQ);
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to remove duplicate element from List