❮ Previous Next ❯

HashTable Interface

Let's see a program for better understanding:

HashtableDemo.java:

import java.util.*;
classHashtableDemo
{
public static void main(String args[])
{
Hashtablehm=new Hashtable();
hm.put(100,"Tapuuu");
hm.put(102,"Silan");
hm.put(101,"Alok");
hm.put(103,"Tilan");
for(Map.Entry m:hm.entrySet())
{
System.out.println(m.getKey()+" "+m.getValue());
}
}
}

Output

103 Tilan
102 Silan
101 Alok
100 Tapuuu

Difference between HashMap and Hashtable:

HashMap and Hashtable both implement java.util.Map interface but there are some differences that Java developers must understand to write more efficient code.

Note that HashMap can be synchronized by

Map m = Collections.synchronizedMap(hashMap);

Summary :

From the interview point of view Collection Framework chapter is fifty percent and the remaining chapters are fifty percent according to my point of view. So this chapter is very important according to the real-time scenario. In this chapter I have given a depth concept about Collection and its implementation classes by taking some demo programs. I also presented Map interface and its implementation classes by taking simple examples. I hope this chapter will make a good platform.

❮ Previous Next ❯



  Tutorials

Popular Links

Contact Us

address Plot No-741,2ND Floor
Opp. Bhagabati Temple,Jayadev Vihar
      Bhubaneswar-751013
      Email: info@silantechnology.com
      Phone: 0674-2361252
address
39877, sundale dr, apt#101, Fremont, California 94538, USA
       Phone: +1(262)388-7619

facebook twitter google linked in

© 2018 Silan Technology. All Rights Reserved