| Author |
What kind of Objects can a Hashtable hold?
|
Ivaturi Srinivas
Ranch Hand
Joined: Jun 03, 2003
Posts: 42
|
|
We know that Hashtable holds objects. Can it hold all types of objects? ot Is there any reservation on this? Thanks Srinivas Ivaturi
|
 |
Sahul Yasin
Ranch Hand
Joined: Aug 28, 2002
Posts: 48
|
|
from jdk doc . Any non-null object can be used as a key or as a value of an Hashtable. Regards, Yasin.
|
Regards,<br />Yasin<br />SCJP,SCWCD,SCBCD
|
 |
Jose Botella
Ranch Hand
Joined: Jul 03, 2001
Posts: 2120
|
|
Welcome to the Ranch Yasin. Hastable API says: To successfully store and retrieve objects from a hashtable, the objects used as keys must implement the hashCode method and the equals method. The Map interface adds: Note: great care must be exercised if mutable objects are used as map keys. The behavior of a map is not specified if the value of an object is changed in a manner that affects equals comparisons while the object is a key in the map. A special case of this prohibition is that it is not permissible for a map to contain itself as a key. While it is permissible for a map to contain itself as a value, extreme caution is advised: the equals and hashCode methods are no longer well defined on a such a map.
|
SCJP2. Please Indent your code using UBB Code
|
 |
 |
|
|
subject: What kind of Objects can a Hashtable hold?
|
|
|