Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to remove duplicate element from List

 
rushikesh kale
Ranch Hand
Posts: 41
Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use a Set instead of a list
 
Guido Sautter
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 457
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't double post, please.
faq.javaranch.com/java/UseOneThreadPerQuestion
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic