wood burning stoves 2.0*
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 Murach's Java Servlets and JSP this week in the Servlets 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);
 
 
subject: How to remove duplicate element from List
 
Similar Threads
How to remove common item between 2 ArrayList
Java 5.0 just syntactic suger?
Filtering out some elements from a ArrayList
Removing element from HTMLDocument
Remove duplicate nodes in DOM