aspose file tools*
The moose likes Java in General and the fly likes How to remove dublicate elements from List Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to remove dublicate elements from List" Watch "How to remove dublicate elements from List" New topic
Author

How to remove dublicate elements from List

shyam sunder prasad
Ranch Hand

Joined: Mar 23, 2011
Posts: 62


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

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

how ?
Murtaza Lokhandwala
Ranch Hand

Joined: Jan 28, 2010
Posts: 35
Use HashSet instead of ArrayList
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Don't use a List, use a Set.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Tomislav Goran
Greenhorn

Joined: May 11, 2011
Posts: 2
You can use Set(HashSet), which, by definition, cannot contain a duplicate
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4391
    
    8

And if you need to keep the ordering as well, use a LinkedHashSet.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to remove dublicate elements from List