Home Java SCJP SCWCD Servlet Submit News Contact Us Site Map


Over 500 magazines for free (including Oracle Magazine)!

Yes all of them are FREE. You can subscribe to ALL of them.
Click here to apply today!

Home > Java > Java Articles

Java Hashtable

A collection allows a group of objects to be treated as a single unit. Map is one of the core interfaces of java collection framework that defines operations for maintaining mappings of keys to values.

Map interface does not implement Collection interface, because it does not contain elements but contains entries of keys and their corresponding values (i.e. called mapping).
Map does not allow duplicate keys. So there is utmost one value that is mapped with the given key. Both key and value must be an Object (Primitive values must be wrapped).

Hashtable implements Map interface (As of the Java 2 platform v1.2, this class has been retrofitted to implement Map, so that it becomes a part of Java's collection framework).
Hashtables will automatically grow when you add too many elements. However, growing requires copying, rehashing and rechaining, which affects its overall performance.

Performance of Hashtable depends on two important factors that are
• Initial Capacity and
• Load Factor

Initial Capacity is the capacity at the time the hash table is created. Load factor determines when to increase the capacity of the Hashtable. The default load factor is 0.75.
Important Note: The initial capacity is not the actual number of elements you plan to store in hashtable. Say for example, if you set initial capacity of 100 and the load factor is 0.75, then the capacity of Hashtable will be automatically increased when it reaches to 75 not 100.

 

Hashtable Constructor >>


Home Java SCJP SCWCD Servlet Site map