A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Programmer Certification (SCJP/OCPJP)
Doubts on Collection framework
Joined: Jun 07, 2005
Jul 12, 2005 22:56:00
book)Objects of class that override the equals() method are used in a collection.If they override the hashcode() method they can also be used as elemens in
and keys in
Q.1)Is it required that the above conditions be met for Objects to be included in a particular type of collection/Map?
Q.2)Is overriding hashcode() method is also enough for the objects to be elements of HashTable/LinkedHashSet/LinkedHashMap???
(from scjp book)Implementing the Comparable interface allows them to be used as elements in sorted sets & sorted maps.
Q.3)Can the elements of sorted sets & maps implement Comparator interface instead of Comparable interface?
(from scjp book)A Comparator interface is used to impose total ordering on the elements and a Comparable interface for natural ordering.
Q.3)I didn't get what these terms 'total ordering' & 'natural ordering' mean?can anybody explain.
subject: Doubts on Collection framework
Set interface in K&B SCJP book
Difference between a Comparator &Comparable
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2013