hi
Both Hashtable and HashMap provides an unordered , unsorted map.
1. if you are not particular in which the elements need to be iterated , then you can use Hashtable or HashMap. but if you want to iterate in particular order and use a Map , then you can go for either LinkedHashMap or TreeMap. LinkedHashMap helps to iterate in the inserted order or access order(last accessed first). The TreeMap helps to iterate in the sorted order.
But Hashtable or HashMap or faster in adding/ removing the elements. But as the elements in TreeMap increases , time taken to add a element in the TreeMap increases. The Iteration of LinkedHashMap is little faster than HashMap.
so if you are not worried in the order in which elements need to be accessed , you can use Hashtable or HashMap.
2. The Hashtable can be used in multi threaded environment which requires that only one
thread should access the data. As Hashtable methods are synchronized , it suits the need. If you don't want to allow null values , you can use Hashtable.
But if your project is based on a single threaded model , then you can use HashMap. HashMap also allows one null key and many null values. The methods of HashMap are not synchronized , so it executes faster and not suitable for multi-threaded environment
if require the data to be iterated in a random particular order and needs a Map then you can use HashMap or Hashtable.
Hashtable for multi-threaded application or web-based application and HashMap for Single Threaded Application or desktop application.
HTH
K Sathya Narayanan