This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What kind of Objects can a Hashtable hold?

 
Ivaturi Srinivas
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
from jdk doc .
Any non-null object can be used as a key or as a value of an Hashtable.
Regards,
Yasin.
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic