What is the main difference between an ArrayList and a Vector? What is the main difference between Hashmap and Hashtable?Differences between ArrayList and Vector:
- Vector is synchronized where as ArrayList is not.
- Vector has a default size of size 10, where as ArrayList has no default size.
- The Vector has a facility to specify the incremental size, where as ArrayList does not
- To view ArrayList, it needs Iterator or Enumeration, while using Vector; it needs Iterator or Enumeration to view its contents.
- ArrayList is not thread-safe whereas Vector is thread-safe.
- A Vector defaults to doubling the size of its array, while the ArrayList increases its array size by 50 percent.
Differences between Hashmap and Hashtable:
- Hashtable is synchronized where as Hashmap is not.
- Hashtable does not allow null values, where as Hashmap does.
- Hashmap does not guarantee the order of map remain constant over time.
- Hashmap implements Map interface. Hashtable implements Dictionary class which is a legacy class.
- Access to the Hashtable is synchronized on the table while access to the HashMap is not.
- Iterator in the HashMap is fail-safe while the enumerator for the Hashtable is not.
|