HashTable Example Java Program
Definition
A hash table is a data structure used to implement an associative array, a structure that can map keys to values. A hash table uses a hash function to compute an index into an array of buckets or slots, from which the desired value can be found.
Syntax
Hashtable variable_name = new Hashtable();
HashTable Example Program
import java.util.Hashtable; class HashTableExample{ public static void main(String[] args){ Hashtable ht = new Hashtable(); ht.put(1,"FIRST"); ht.put(2,"SECOND"); ht.put(3,"THIRD"); ht.put(4,"THIRD"); System.out.println("Hashtable is "+ht); System.out.println("Value of key 2: "+ht.get(2)); System.out.println("Size of the Hashtable is "+ht.size()); } }
Sample Output
Output is: Hashtable is {4=THIRD, 3=THIRD, 2=SECOND, 1=FIRST} Value of key 2: SECOND Size of the Hashtable is 4
Java Collection Programs
- Linked List Example Java Program
- ArrayList Example Java Program
- HashSet Example Java Program
- Clear an Arraylist Example Java Program
- Reversing an ArrayList Example Java Program
- Linked HashSet Example Java Program
- HashMap Example Java Program
- Set Value in ArrayList Example Java Program
- Linked HashMap Example Java Program
- Remove Element from ArrayList Example Java Program
- Identity HashMap Example Java Program
- TreeMap Example Java Program
- TreeSet Example Java Program
- Finding Duplicates in Array Using TreeSet Java Example Program
- HashTable Example Java Program
- EnumSet Example Java Program
- Enum Map Example Java Program
- Wrapper Example Java Program
- Un Modifiable Wrapper Example Java Program
- Iterator Interface Example Java Program
- Sorted Map Interface Example Java Program
- Sorted Set Interface Example Java Program
Read More Articles
- Multiple Inheritance Using Interface Example Java Program
- Single Inheritance Example Java Program
- Multilevel Inheritance Example Java Program
- Hierarchical Inheritance Example Java Program
- Find all Substrings of a given string Example Java Program
- Create Matrix Example Java Program
- Sum Of Three Numbers Example Java Program
- Heap Sort Example Java Program
- Twin Prime Example Java Program
- Compile Time Polymorphism Example Java Program