wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes array, arraylist, vector Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "array, arraylist, vector" Watch "array, arraylist, vector" New topic
Author

array, arraylist, vector

Bernard Sigmund Gustav
Ranch Hand

Joined: Dec 20, 2005
Posts: 170
i want to search an array or arraylist to remove duplicate entries
is there a method to do that or i have to make a search process for it?
[ March 01, 2006: Message edited by: shuini gustav ]
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
Originally posted by shuini gustav:
i want to search an array or arraylist to remove duplicate entries
is there a method to do that or i have to make a search process for it?

[ March 01, 2006: Message edited by: shuini gustav ]


final List<E> uniqueEntries = newArrayList<E>(new HashSet<E>(theList));


Tony Morris
Java Q&A (FAQ, Trivia)
Bernard Sigmund Gustav
Ranch Hand

Joined: Dec 20, 2005
Posts: 170
Originally posted by Tony Morris:


final List<E> uniqueEntries = newArrayList<E>(new HashSet<E>(theList));


gee thanks.
but i really am new to this and i do not understand HashSet as yet
what's <E> ? will that statement automatically remove all the duplicate entries in my arraylist or array?
Bernard Sigmund Gustav
Ranch Hand

Joined: Dec 20, 2005
Posts: 170
thanks for the tip
i looked that up and decided to implement a TreeSet instead.

i did that with this line which automatically removes all duplicate entries:
ArrayList catlist = new ArrayList( new TreeSet(category) );

thanks
Renu Radhika
Ranch Hand

Joined: Oct 21, 2005
Posts: 243
but treeSet will sort it also.you should use it only if you want unique elements in a sorted way
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
What may be likely is that you want subsequent duplicates removed from the list of elements, but not have the ordering of the elements altered. In that case, LinkedHashSet will do the job:


Don't get me started about generics... I used to think the free dogma generated by the empty category could be our foundation. I was off by an infinity of monads!


There is no emoticon for what I am feeling!
 
jQuery in Action, 2nd edition
 
subject: array, arraylist, vector
 
Similar Threads
2D array
Naming Objects
Filling an ArrayList
findByCriteria()
Sending Multiple Emails