• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Hashmap vs hashtable ....

 
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey ranchers.. just wanna make sure I know pretty much all (or the main) differences between hashmap and hastables.
1o.) according to RHE book:
Hashtable does not allow the null value to be stored, although it makes some efforts to support multithreaded use...
2o.) reading a post at javaranch
hashtable are synchronized, hashmaps are not.
any others??
thanks
 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HashMap extends AbstractMap
HashTable Extends Dictionary
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You may also want to have a look at the following article from the August '02 Javaranch newsletter:
Storing Objects in Java Part 3 - The Map Interface by Thomas Paul
See also the following discussion in the Performance forum:
Hashtable vs Hashmap by Max Habibi
And this too:
Utilizing the Map Interface from the Collections Framework
[ October 21, 2002: Message edited by: Valentin Crettaz ]
 
Valentin Crettaz
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One more article that appeared in the July 02 edition of Java Pro:
Using Hashtables in Java
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another important difference is that Hashtable is synchronized and Hashmap is not. This is critical in knowing, because of Thread access issues. A Thread can obtain a monitor on a Hashtable without any extra coding. Any code utilizing a Hashmap that is needed to be Thread safe must provide synchronized code block when accessing Hashmap. Same thing applies when talking about Vector versus an ArrayList. The newer implementations such as Hashmap and ArrayList do not burden the programmer with the overhead of synchronization. With Vector and Hashtable you have no choice.
 
Cowgirl and Author
Posts: 1589
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy -
I'm too lazy to follow all the links, so although I'm sure this is mentioned in the other references, I just wanted to summarize what's important for the exam:
* Hashtable methods are synchronized, HashMap are not.
* Hashtable does not accept null anything (so, you can't have a null key and you can't have any null values)
* HashMap allows both a null key (obviously, just one) and null values
And... bonus reply here
Don't forget LinkedHashMap -- big difference between it and the other two (as far as the exam is concerned) is that there's no guaranteed iteration order for Hashtable and HashMap (and remember, you're not iterating over the actual Hashtable or HashMap, you're iterating over just the *values*) --
but with LinkedHashMap you get a choice of two different orderings: by insertion order, or by access order.
Cheers,
Kathy "too lazy to link" Sierra :roll:
 
You ridiculous clown, did you think you could get away with it? This is my favorite tiny ad!
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic