In this tutorial, we are going to discuss one of concept (Hashtable ) of Collection framework.
In this tutorial, we are going to discuss one of concept (Hashtable ) of Collection framework.In this tutorial, we are going to discuss one of concept (Hashtable ) of Collection framework.
Hashtable :
Hashtable class is defined in java.util package and implementation of Dictionary. It maps keys to the values. You can use any non-null object as a key and as a value. When you increase the entries in the Hashtable, the product of the load factor and the present capacity is increased automatically as it calls the rehash method.
Hashtable defines four constructor -
Hashtable defines many method, Here we are defining some of them -
Example :
package collection; import java.util.Enumeration; import java.util.Hashtable; public class HashTableExample { public static void main(String[] args) { Hashtable ht = new Hashtable(); Enumeration student; String name; int roll; ht.put("Roxi", 1); ht.put("Jackson", 2); ht.put("Mandy", 4); ht.put("Tara", 5); student = ht.keys(); while (student.hasMoreElements()) { name = (String) student.nextElement(); System.out.println(name + ": " + ht.get(name)); } System.out.println(); } }
Output :
Jackson: 2 Roxi: 1 Tara: 5 Mandy: 4