Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java in General
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Java in General
How to remove dublicate elements from List
shyam sunder prasad
Ranch Hand
Posts: 62
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; public class MainClass { public static void main(String args[]) { String init[] = { "One", "Two", "Three", "One", "Two", "Three" }; List list1 = new ArrayList(Arrays.asList(init)); } }
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
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Use HashSet instead of ArrayList
Paul Sturrock
Bartender
Posts: 10336
I like...
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Don't use a List, use a Set.
JavaRanch FAQ
HowToAskQuestionsOnJavaRanch
Tomislav Goran
Greenhorn
Posts: 2
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
You can use Set(HashSet), which, by definition, cannot contain a duplicate
Matthew Brown
Bartender
Posts: 4568
9
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
And if you need to keep the ordering as well, use a
LinkedHashSet
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Generics doubt
scjp generic question
SCJP 5: Question on Generics
splitting up lists
How to sort a list of lists
More...