I'd lean towards Comparator. If you implement Comparable (and you might want to) it should be compatible with Equals. If you compare on address only for the purpose of duplicates you're saying any two objects with the same address are equal, and that may not be intuitive to future generations of coders who have to maintain the code. A special-purpose comparator would be created and used local to the code that adds objects to the list and would not influence how the objects behave at other times.
Look at the doc for Comparable and Comparator (right after SortedList ) and see if all that makes sense.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Joined: Sep 10, 2004
thanks, I built the comparator and it works. so now I have an arraylist that is sorted by address. I need to convert it to the sortedSet what is the best way to do it and make sure no dupp will occur?
Joined: May 29, 2003
That what Sets are for -- just add all your elements to the Set. It will take care of the rest for you.