2

Does java use open addressing or chaining to implementing Hashtable?

Is one method or the other required by some specification/certification?

4
  • 13
    What's easier than checking the source? docjar.com/html/api/java/util/Hashtable.java.html Commented Aug 4, 2011 at 18:17
  • 2
    Java probably doesn't require either. Individual implementations likely do whatever they think works best, as things like that are implementation details. Commented Aug 4, 2011 at 18:18
  • 3
    You should also look at HashMap, LinkedHashMap and ConcurrentHashMap which are all subtly different. I would suggest you not use the old Hashtable class unless you have to. Commented Aug 4, 2011 at 18:21
  • See How do HashTables deal with collisions? Commented Aug 5, 2011 at 2:18

3 Answers 3

2

If you look at the Javadoc for Hashtable, you'll notice that it doesn't specify which hash scheme it uses. This means that any compliant Java implementation could implement this object however it sees fit, as long as it obeys the complexity guarantees specified in the interface. A compliant implementation could use chaining, quadratic hashing, Robin hood hashing, dynamic perfect hashing, Cuckoo hashing, etc. as long as the guarantees specified in the interface were met.

From a client perspective, you shouldn't need to worry about this, though.

Sign up to request clarification or add additional context in comments.

1 Comment

+1 for relying on the documentation and not the implementation.
1

Both java.util.HashMap and java.util.Hashtable use some sort of chaining, at least in the implementation used in the Sun/Oracle JRE and the OpenJDK one.

Comments

0

The specification is in the Javadoc.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.