HashTable in Java

Advertisements

Prev Tutorial Next Tutorial

HashTable in Java

HashTable is Implementer class of Map interface and extends Dictionary class. HashTable does not allows null key and null values, these elements will be stored in a random order.

Points to Remember

  • HashTable is a legacy class, which will uses hashing technique (the elements will be stored in unsorted or un-order format).
  • HashTable stored the elements in key values formate.
  • HashTable does not allows null keys and null values.
  • HashTable is Synchronized.
  • HashTable allows heterogeneous elements.
  • For retrieve elements from HashTable you can use foreach loop, Iterator Interface and Enumeration.

Note: HashTable class also contains same methods like HashMap.

Difference between HashMap and HashTable

HashMapHashTable
1HashMap is a new class in java API.HashTable is a legacy class in java API.
2HashMap is not Synchronized.HashTable is Synchronized.
3HashMap allows maximum one null key and multiple null value.HashTable does not allows any null key and null values.

Limitations of HashTable

  • Hashtable class object is enable to read the data from property file / resource bundle file.
  • Hashtable class object is unable to develop flexible application.

Example of HashTable

import java.util.*;
class HashTableDemo
{
public static void main(String args[])
{  
   
  HashTable<Integer,String> ht=new HashTable<Integer,String>();  
  ht.put(1,"Deo");  
  ht.put(2,"zen");  
  ht.put(3,"porter");  
  ht.put(4,"piter");  
  
   System.out.println(ht);  
 }  
}  

Output

[1=Deo, 2=zen, 3=porter ,4=piter]

Prev Tutorial Next Tutorial

Advertisements

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 8076671483

Pure VPN Privide Lowest Price VPN Just @ $1.65. Per Month with Non Detected IP Lowest Price Non Detected IP VPN

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

Download Projects

Advertisements


Buy Websites 9999595223

Buy Fresh and Payment Receive Media.net Account with Website. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs