This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
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

JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to remove duplicate element from List" Watch "How to remove duplicate element from List" New topic

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.

Bill Shirley - bshirley -
if (Posts < 30) JavaRanchFAQ);
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: How to remove duplicate element from List
It's not a secret anymore!