There is no method called comparator in java.util.Set. Some set's use a comparator do order there elements, such as a TreeSet. But then the elements need to implement the Comparable interface or a Comparator must be provided a creation time.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Vinoth Kumar Kannan wrote:Yeah, Set doesn't have one, but TreeSet has.
That should be Code against interfaces as much as possible. Since SortedSet declares the comparator() method it's better to use that interface. That allows you to more easily switch to a different implementation (like ConcurrentSkipListSet) if needed.
This reminds me of the "what happens next?" bit on a home video TV programme. They show half the video, and about one second before something strange happens, the commercials come on, so you have to wait several minutes to find out what happens.
Anyway, let's have a programming "what happens next?"