Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Jasmine Grant   on Jul 15 In Java Category.

  
Question Answered By: Mehreen Malik   on Jul 15

i have taken this content from the source files of the HashMap.java &
Hashtable.java


==========================================================================


Hashmap


Hash table  based implementation of the Map interface. This implementation
provides all of the optional map operations, and permits null values and the
null key. (The HashMap class is roughly equivalent to Hashtable, except that it
is unsynchronized and permits nulls.) This class makes no guarantees as to the
order of the map; in particular, it does not guarantee that the order will
remain constant over time.


This implementation provides constant-time performance for the basic operations
(get and put), assuming the hash function disperses the elements properly among
the buckets. Iteration over collection views requires time proportional to the
"capacity" of the HashMap instance (the number of buckets) plus its size (the
number of key-value mappings). Thus, it's very important not to set the initial
capacity too high (or the load factor too low) if iteration performance is
important.


An instance of HashMap has two parameters that affect its performance: initial
capacity and load factor. The capacity is the number of buckets in the hash
table, and the initial capacity is simply the capacity at the time the hash
table is created. The load factor is a measure of how full the hash table is
allowed to get before its capacity is automatically increased. When the number
of entries in the hash table exceeds the product of the load factor and the
current capacity, the capacity is roughly doubled by calling the rehash method.


Hashtable


This class implements a hashtable, which maps keys to values. Any non-null
object can be used as a key or as a value.


To successfully store and retrieve objects from a hashtable, the objects used as
keys must implement the hashCode method and the equals method.


An instance of Hashtable has two parameters that affect its performance: initial
capacity and load factor. The capacity is the number of buckets in the hash
table, and the initial capacity is simply the capacity at the time the hash
table is created. Note that the hash table is open: in the case of a "hash
collision", a single bucket stores multiple entries, which must be searched
sequentially. The load factor is a measure of how full the hash table is allowed
to get before its capacity is automatically increased. When the number of
entries in the hashtable exceeds the product of the load factor and the current
capacity, the capacity is increased by calling the rehash method.

Share: 

 

This Question has 2 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Hashmap Or get search suggestion and latest updates.


Tagged: