I know about SortedSet
, but in my case I need something that implements List
, and not Set
. So is there an implementation out there, in the API or elsewhere?
It shouldn't be hard to implement myself, but I figured why not ask people here first?
I know about SortedSet
, but in my case I need something that implements List
, and not Set
. So is there an implementation out there, in the API or elsewhere?
It shouldn't be hard to implement myself, but I figured why not ask people here first?
I needed something like that, so I went to the commons collections and used the SetUniqueList, but when I ran some performance test, I found that it seems not optimized comparing to the case if I want to use a Set and obtain an Array using the Set.toArray() method, the SetUniqueTest took 20:1 time to fill and then traverse 100,000 Strings comparing to the other implementaion, which is a big deal difference, so If you worry about the performance, I recommend you to use the Set and get a Array instead of using the SetUniqueList, unless you really need the logic of the SetUniqueList, then you need to check other solutions...
The testing code main method:
public static void main(String[] args) {
}
Regards Mohammed Sleem http://abusleem.net/blog
You should seriously consider dhiller's answer:
new ArrayList(set)
(or anew LinkedList(set)
, whatever).I think that the solution you posted with the
NoDuplicatesList
has some issues, mostly with thecontains()
method, plus your class does not handle checking for duplicates in the Collection passed to youraddAll()
method.NOTE: it does not take subList implementation into account.
Why not encapsulate a set with a list, sort like:
This leaves the other implementation for someone who is a real master of Collections ;-)
I just made my own UniqueList in my own little library like this:
I have a TestCollections class that looks like this:
Works fine. All it does is it adds to a set if it does not have it already and there's an Arraylist that is returnable, as well as an object array.