Friday, August 22, 2008

Differences: HashTable Vs HashMap

HashTable Vs HashMap
  • Hashtable is synchronized and thread-safe.HashMap is asynchronized and faster.
  • HashMap implements Map interface.By using the Map interface it can switched between TreeMap &HashMap.
  • HashMap permits the null values as key or value but Hashtable does not.
  • HashMap does not guaranteed to store the values in a constant order over a period of time.
  • Synchronization can be achieved by the HashMap by using java.util.collections.synchronizedMap(yourHashMap).This feature is added in JDK1.5.


When to go What?

  • Is your operation is multithreaded ?: HashTable(less than jdk1.5).
  • Is the datatype of key is Integer ? : HashTable has better performance if the data type of the key is Integer.

Thursday, August 21, 2008

Difference between Arraylist Vs Vector

Arraylist Vs Vector


  • Vector is synchronous but arraylist is asynchronous.
  • Vector & Hashtables are introduced in JDK1.0 but Araaylist & HashMaps are introduced in JDK1.2.
  • vector is comparatively slow with Arrraylist.

When to use what?

  • If your data is accessed by multiple threads then go for Vector.
  • If your list is a local variable then go for Arraylist blindly.
  • If your data is accessed by a single thread then go for Arraylist.