0

I've been going through Java API java.util.HashMap and java.util.Hashtable

I've understood the internal implementation of get(Key k) and put(Key k, Value v)methods of HashMap, and Hashtableseems almost same to me in terms of get(k) and put(k,v)method.

Please tell me does Hashtable internally work in the same way as it is in HashMap or differently?

I know other stuff about synchronization, default capacity and null key/values, but apart from these does it differ in terms of its internal implementation of get and put method.

I've already checked java source code for the mentioned class and also visited this link: Differences between HashMap and Hashtable? I'd like to know about the internal get and put method implementations of the classes.

Please share your knowledge. Thanks!

Community
  • 1
  • 1
inityk
  • 317
  • 1
  • 7
  • 17
  • 1
    In additional to the link above, in Java 8 there was significant changes to HashMap meaning there could be even more differences. I suggest you refer to the source code. – Peter Lawrey Dec 04 '15 at 14:25
  • @PeterLawrey, thanks but I've gone through the source code and I'm aware of the HashMap enhancements in Java 8. The way Hashmap stores data via put(k, v) method and retrieves via get(k) Is this the same with Hashtable? – inityk Dec 04 '15 at 14:50
  • I haven't review Java 8 Hashtable however in Java 7 while broadly the same it was not exactly the same e.g. in terms of how it agitated the hash code etc. – Peter Lawrey Dec 04 '15 at 15:04
  • @PeterLawrey, okay so the way they implement hashcode() is different from each other? I.e HashMap and Hashtable? – inityk Dec 04 '15 at 17:49
  • 1
    `Hashtable` has essentially been deprecated for over a decade and a half. Any new code (even synchronized) should be using `HashMap`, `ConcurrentHashMap`, or a `Collections.synchronizedMap` wrapper for `HashMap`. – Powerlord Dec 04 '15 at 17:55
  • Neither implements hashCode(), that is for the key class. They use this hashCode differently. – Peter Lawrey Dec 05 '15 at 00:01

0 Answers0