>>> Hello!
>>> I have the following method overriding Collection.addAll:
[quoted text clipped - 27 lines]
>
> Hmm how does this skip duplicates?
A set contains no duplicates, so if the collection were the list "A",
"B", "A" the treeset would contain "A", "B". However, the TreeSet
iterator is in compareTo order, not the List order.
If the collection is too large for linear scanning, I would implement
the no-duplicates list using two data structures, a HashSet for
determining which elements are eligible for adding, and a List to
preserve order.
Patricia
Daniel Dyer - 11 Aug 2007 20:14 GMT
>>>> Is there any faster way without overriding other methods?
>>>> Karsten
[quoted text clipped - 6 lines]
> "B", "A" the treeset would contain "A", "B". However, the TreeSet
> iterator is in compareTo order, not the List order.
A LinkedHashSet may be preferable if preserving the order is important:
http://java.sun.com/j2se/1.5.0/docs/api/java/util/LinkedHashSet.html
Dan.

Signature
Daniel Dyer
http//www.uncommons.org
Patricia Shanahan - 11 Aug 2007 21:12 GMT
>>>>> Is there any faster way without overriding other methods?
>>>>> Karsten
[quoted text clipped - 10 lines]
>
> http://java.sun.com/j2se/1.5.0/docs/api/java/util/LinkedHashSet.html
I don't think LinkedHashSet has the ability to addAll at a specified
index. The following is a quote from the original article:
> I have the following method overriding Collection.addAll:
>
> @Override
> public boolean addAll(int index, Collection<? extends E> cln)
> {
Collection does not have a two argument addAll. List does, so I suspect
the new class is supposed to implement List.
Patricia
Danno - 13 Aug 2007 00:06 GMT
> >>>>> Is there any faster way without overriding other methods?
> >>>>> Karsten
[quoted text clipped - 24 lines]
>
> Patricia
Very nice Patricia,
I also found this on commons-collections
http://commons.apache.org/collections/api-release/org/apache/commons/collections
/set/ListOrderedSet.html