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
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);
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.
Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.
We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc