-1

I found these description in JDK 1.7's HashTable comment.

If a thread-safe implementation is not needed, it is recommended to use {@link HashMap} in place of {@code Hashtable}. If a thread-safe highly-concurrent implementation is desired, then it is recommended to use {@link java.util.concurrent.ConcurrentHashMap} in place of {@code Hashtable}.

Then I think it have no situations to use HashTable.

user207421
  • 305,947
  • 44
  • 307
  • 483
xin zhao
  • 600
  • 2
  • 11
  • 5
    Yes, it is fair to say that – Sleiman Jneidi Jul 01 '16 at 09:00
  • 1
    Correct, it's obsolete but you'll see it's used in places (eg a parent of java.util.Properties). Similarly `java.util.Vector` has been replaced by `java.util.ArrayList` and `Collections.synchronizedList(List)` – lance-java Jul 01 '16 at 09:02
  • 5
    What part of your question isn't answered by the text you quoted? – user207421 Jul 01 '16 at 09:49
  • @EJP the text doesn't cover the case where thread safety is required but high concurrency is not expected. – davmac Jul 01 '16 at 09:56
  • @EJP When thread safety is required but high concurrency is not expected, is HashTable more efficient than ConcurrentHashMap? – xin zhao Jul 01 '16 at 10:16
  • @xinzhao probably it is, very slightly; however, if you were concerned about performance, it would probably be better to re-work your design so that you didn't require thread-safety from the hashtable and then use `HashMap` instead. My comment above is not intended to imply that `Hashtable` is not obsolete, I was merely pointing out that the text you quote does _not_ in fact completely answer your question. – davmac Jul 01 '16 at 10:19
  • @davmac I see, thank you very much. – xin zhao Jul 01 '16 at 10:20
  • Possible duplicate of [Differences between HashMap and Hashtable?](http://stackoverflow.com/questions/40471/differences-between-hashmap-and-hashtable) – dimo414 Jul 10 '16 at 00:41

1 Answers1

2

Yes, it's been more or less obsolete since java 1.2. You should use HashMap or ConcurrentHashMap.

Andrea Bergia
  • 5,502
  • 1
  • 23
  • 38