This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hashmap

 
navat venu
Ranch Hand
Posts: 66
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could anyone explain in which scenario hashmap and hashtable will be used?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not an advanced question. Moving...
 
Saket Barve
Ranch Hand
Posts: 229
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Navat,

HashTable and HashMap are data structures providing key-value access to data. Following are the basic differences between the two are:
1. HashTable provides default synchronization whereas HashMap does not.
2. Hashtable does not permit null values whereas HashMap does.

Saket
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you asking what HashMap and Hashtable are, or do you already know that and do you want to know when you should use one or the other?

HashMap and Hashtable are both associative array data structures.

Hashtable is a legacy collection class. You shouldn't use it anymore; instead, you should always use HashMap. If you really need a synchronized map, you should use the method java.util.Collections.synchronizedMap(...), for example:
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hashtable should be used in the past, HashMap in the future.

Be darned sure you know what a synchronized map does before you count on it for thread safety. It's very likely you'll want to synchronize all the code that accesses the map instead of using a synchronized map.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic