• Post Reply Bookmark Topic Watch Topic
  • New Topic

HashMap Vs HashTable  RSS feed

 
Ranch Hand
Posts: 1489
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I retrived all the records thru jdbc ResultSet from the DB and plan to store it in the HashMap / HashTable. Then i will call this HashMap/HashTable in my Singleton class.
Which one is better - HashMap / Hashtable?
 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Depends on the implementation of your method though, if your collection is a member in your singleton and you use a setter then go for a HashMap within a synchronized context.

Regards
Balaji Pattabhiraman
 
kri shan
Ranch Hand
Posts: 1489
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bajji Pat, I am not getting meaning of this 'use a setter' ??
 
Bajji Pat
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Krishan,

I meant using a setter method to modify the Class's member variables.(i.e. have private member variables and use methods(public) to modify them instead of directly setting them).

Regards
Balaji Pattabhiraman
[ April 15, 2005: Message edited by: Bajji Pat ]
 
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use a HashMap - it handles null keys better (remembering as Bajji Pat has pointed out it is unsynchronized).
 
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or, more accurately, don't use Hashtable. Ever. HashMap is better, and if you need synchronization, java.util.Collections provides a mechanism to get a synchronized map.
 
kri shan
Ranch Hand
Posts: 1489
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How java.util.Collections provides a mechanism to get a synchronized map ??
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!