Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Hashtable vs HashMap

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

What is the major difference between a hashtable and hashmap? Thanks.
 
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hashtable is synchronized, HashMap not.
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HashMap class is not thread-safe nad permits one null key,the HashTable class is thread-safe and permits non-null keys and values only.
The Thread-safety that <i>HashTable</i> class provides has a performance penalty. HashTable class is a legay class that has been retrofitted to implement the Map interface.
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you are considering using HashTable or Collections.synchronizedMap(new HashMap())
because its methods are "thread-safe", check out java.util.concurrent.ConcurrentHashMap first:

Brian Goetz's articl on ConcurrentHashMap

ConcurrentHashMap API
 
Ronnie Ho
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all.
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic