aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes What kind of Objects can a Hashtable hold? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "What kind of Objects can a Hashtable hold?" Watch "What kind of Objects can a Hashtable hold?" New topic
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What kind of Objects can a Hashtable hold?
 
Similar Threads
Hashtable Retrieve
Session variable
Hashtable casting error
Can vectors only hold objects?
Hashtables, objects & casting