File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes difference between hashmap&hashtable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "difference between hashmap&hashtable" Watch "difference between hashmap&hashtable" New topic

difference between hashmap&hashtable

Ksam kumar

Joined: Jul 13, 2007
Posts: 1
i want detail above question.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46349
Welcome to the Ranch.

Hashtable and HashMap. Please check the spelling.

Go to the API documentation and look for Map. When you open that, it gives brief details of what a Map is; you will find both the classes you quoted are Maps.

Read the descriptions of both classes. Particularly look for handling of null values, whether any methods are synchronized, whether there are any methods returning Iterators or Enumerations, and when the classes were introduced.

Most people doing modern Java programming use HashMap and don't use Hashtable, although this is not a "rule" or "regulation."

[edit]Additional: You will find HashMap and Hashtable underlined in blue when you find Map; those are links which will lead you where you want to go. [/edit]
[ July 13, 2007: Message edited by: Campbell Ritchie ]
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15082

Hathtable is a legacy collection class, i.e., a legacy class from before Java version 1.2, when the Collections framework was added to Java. HashMap is more or less the replacement for Hashtable since Java 1.2.

In new programs, you should use HashMap and not Hashtable.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Remko Strating
Ranch Hand

Joined: Dec 28, 2006
Posts: 893
Hashtable has his methods synchronized and Hashtable doesn't allow Null-values and a Null-key.

Remko (My website)
SCJP 1.5, SCWCD 1.4, SCDJWS 1.4, SCBCD 1.5, ITIL(Manager), Prince2(Practitioner), Reading/ gaining experience for SCEA,
I agree. Here's the link:
subject: difference between hashmap&hashtable
It's not a secret anymore!