2

I usually work in non multi threaded environment so usually go for HashMap instead of Hashtable. I know the difference between both and I also know Hashtbale was introduced way before Java Collection framework was introduced. If we go through the Hashtable source code we can find

public class Hashtable<K,V>
extends Dictionary<K,V>
implements Map<K,V>, Cloneable, java.io.Serializable {...

My point is Hashtable was introduced way before Java Collection framework(So way before Map was introduced). Since Hashtable implements Map, Hashtable implementation has been modified.My questions is why is Hashtable not a part of Java Collection Framework when Map is?

Aniket Thakur
  • 66,731
  • 38
  • 279
  • 289
  • 1
    It may implement the Map interface (which isn't much of a stretch since it already had the functionality), but it does not extend AbstractMap, and *perhaps* that is key. – Hovercraft Full Of Eels May 19 '13 at 06:18
  • 3
    Well, according to javadocs: _As of the Java 2 platform v1.2, this class was retrofitted to implement the Map interface, making it a member of the Java Collections Framework._ See: http://docs.oracle.com/javase/6/docs/api/java/util/Hashtable.html – makasprzak May 19 '13 at 06:23
  • Because it came first, as the respective `@since` comments show clearly. – user207421 May 19 '13 at 06:37

2 Answers2

2

In the last paragraph of API document of Hashtable

As of the Java 2 platform v1.2, this class was retrofitted to implement the Map interface, making it a member of the Java Collections Framework.

aberrant80
  • 12,815
  • 8
  • 45
  • 68
johnchen902
  • 9,531
  • 1
  • 27
  • 69
2

Hashtable was introduced as part of Java 1.0 where it didn't use Map. In version 1.2, it was changed to implement Map and hence, became part of the Collections framework. http://docs.oracle.com/javase/7/docs/api/java/util/Hashtable.html

JamesB
  • 7,774
  • 2
  • 22
  • 21
  • That makes sense. But i am surprised whenever we refer to Java Collection framework no one ever refers to Hashtable. So Hashtable is a part of Java Collection Framework. Thanks a lot! – Aniket Thakur May 19 '13 at 06:29
  • @AniketThakur That's probably because `HashMap` or `ConcurrentHashMap` are usually preferred over `HashTable`, as stated in the [Java docs for `HashTable`](http://docs.oracle.com/javase/7/docs/api/java/util/Hashtable.html). – Lone nebula May 19 '13 at 06:41