File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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: 4240
    
    7

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
 
Similar Threads
scjp generic question
SCJP 5: Question on Generics
Generics doubt
How to sort a list of lists
splitting up lists