SCJP 1.4 - 95% [ My Story ] - SCWCD 1.4 - 91% [ My Story ]
Performance is a compulsion, not a option, if my existence is to be justified.
Regards,<br />Seb<br /> <br />SCJP 1.4
Originally posted by Niranjan Deshpande:
... Please give me a verbose explanation...
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Originally posted by Niranjan Deshpande:
TreeSet list = new TreeSet(new Car());
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Thanks & Regards<br /> <br />-Srikanth
Originally posted by Mark Spritzler:
#5 is correct. the correct method for the Comparable method is public int compareTo(Object o)
the method compare(Object o1, Object o2) is the methods signature for a Comparator.
Mark
Regards,<br />Seb<br /> <br />SCJP 1.4
Thanks & Regards<br /> <br />-Srikanth
Note that the ordering maintained by a set (whether or not an explicit comparator is provided) must be consistent with equals if it is to correctly implement the Set interface. (See Comparable or Comparator for a precise definition of consistent with equals.) This is so because the Set interface is defined in terms of the equals operation, but a TreeSet instance performs all key comparisons using its compareTo (or compare) method, so two keys that are deemed equal by this method are, from the standpoint of the set, equal. The behavior of a set is well-defined even if its ordering is inconsistent with equals; it just fails to obey the general contract of the Set interface.
today's feeble attempt to support the empire
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
|