• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to remove dublicate elements from List

 
shyam sunder prasad
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


from list1, i need to delete all duplicate values except one

resultant list would be { "One", "Two", "Three"};

how ?
 
Murtaza Lokhandwala
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use HashSet instead of ArrayList
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't use a List, use a Set.
 
Tomislav Goran
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use Set(HashSet), which, by definition, cannot contain a duplicate
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And if you need to keep the ordering as well, use a LinkedHashSet.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic