Hi all,
can any one tell me how to find unique values in array list?
Thanks in advance..
anand01 0 Junior Poster
Recommended Answers
Jump to PostYou need to tell us the type of values you have in the `List'. Assuming you have simple strings in the list, you can do:
// untested final List<String> lst = Arrays.asList("a", "b", "c", "a", "c", "b"); final Set<String> set = new HashSet<String>(lst); System.out.printf("Original list: %s%n", lst); …
Jump to Post@~s.o.s~ (-: why you have to sent here your post twice :-)
Sometimes happens when there is lag on your internet connection or on server side.
~s.o.s~ Set is obvious solution :P
Jump to PostRight, because Set guarantees unique elements, not necessarily in sorted order. If you need to maintain the order of elements, use `TreeSet<String>`. Just make sure the objects you insert in the TreeSet implement natural ordering (by implementing Comparable) or be ready to provide your own custom ordering (implement Comparator). Anyways, …
All 10 Replies
Taywin 312 Posting Virtuoso
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster
anand01 0 Junior Poster
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster
mKorbel 274 Veteran Poster
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster
anand01 0 Junior Poster
anand01 0 Junior Poster
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster
anand01 0 Junior Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.