• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

HashMap Vs HashTable

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can somebody tell me what is the difference between HashMap and hashTable and which one is more better than other and why.
 
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HashMap & Hashtable both use hashing mechanism and store the entries as key value pairs.The difference between them is hashmap can store one null key & multiple null values,but hashtable doesn't allow anything(either a key or value) which is null.One more difference is hashtable is synchronized where as hashmap is not.Deciding the better one depends on ur design.

Regards,
Priya.
 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jothi,

Can u please explain whats do u mean by "HashMap can hold one null key and multiple null values" ??
Whats the advantage of synchronised HashTable? When can v use it?

Can any one explain this pls...
 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since Hashtable is synchronized it can be used safely in a multithreaded program guaranteeing exclusivity of access to a thread that holds its lock. HashMap does not have this functionality.
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ja,

You are allowed only one null key in a HashMap whilst your are not allowed to use null in a HashTable as a key or value.

Hope this helps.

An
 
It's a pleasure to see superheros taking such an interest in science. And this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic