Rule Definition
Since Hashtables are all synchronized - yet synchronization is usually not needed -, they are much slower than the various List and Map implementations
Remediation
When synchronization is not need, prefer List and Map implementations
Violation Code Sample
import java.util.*; import java.lang.*; import java.io.*; class Ideone { public static void main(String args[]) { //----------hashtable ------------------------- Hashtable<Integer,String> ht=new Hashtable<Integer,String>(); ht.put(101," ajay"); ht.put(101,"Vijay"); ht.put(102,"Ravi"); ht.put(103,"Rahul"); System.out.println("-------------Hash table--------------"); for (Map.Entry m:ht.entrySet()) { System.out.println(m.getKey()+" "+m.getValue()); } } }
Fixed Code Sample
import java.util.*; import java.lang.*; import java.io.*; class Ideone { public static void main(String args[]) { //----------------hashmap-------------------------------- HashMap<Integer,String> hm=new HashMap<Integer,String>(); hm.put(100,"Amit"); hm.put(104,"Amit"); // hash map allows duplicate values hm.put(101,"Vijay"); hm.put(102,"Rahul"); System.out.println("-----------Hash map-----------"); for (Map.Entry m:hm.entrySet()) { System.out.println(m.getKey()+" "+m.getValue()); } } }
Reference
https://www.javatpoint.com/difference-between-hashmap-and-hashtable https://medium.com/@mr.anmolsehgal/hashtable-vs-hashmap-vs-concurrenthashmap-4aa0ff1eecc4
Related Technologies
JEE
Technical Criterion
Efficiency - Memory, Network and Disk Space Management
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.