使用 Java 字典...使用哈希表? [英] Using Java Dictionary...use a Hashtable?
问题描述
我有点惊讶没有人问过这个特定案例,因为它在 Java 标准库中有点奇怪的不一致:
I'm a bit surprised no one has asked about this specific case, cause it's kind of a weird inconsistency in the java standard libraries:
我正在使用带有自定义标签的 Swing JSlider;唯一可用于分配标签的库调用是:setLabelTable(Dictionary labels)
I'm using swing JSliders with custom labels; the only library call available to assign labels is: setLabelTable(Dictionary labels)
但是 Dictionary 是一个抽象类,它在标准库中唯一已知的子类是 Hashtable,它的 api &各种 IDE 都抱怨,因为它过时了".
But Dictionary is an abstract class, and its only known subclass in the standard lib is Hashtable, which the api & various IDE's complain about because it's "obsolete."
显而易见的事情就是使用哈希表,但我想知道两件事:
The obvious thing to do is just use the Hashtable, but I'm wondering two things:
- 有没有更好的方法来解决这个问题?
- 如果Hashtable是唯一的这个(在我看来)相当重要的库的可用类调用,它在什么基础上过时"了?
谢谢!
推荐答案
Hashtable 过时的原因是 因为它被Hashmap替换了.
The reason Hashtable is obsolete is because it was was replaced with Hashmap.
然而,为了给 setLabelTable 分配标签,Hashtable 的不足"不是问题.
However, for the purposes of assigning labels to a setLabelTable, the "deficiencies" of Hashtable are not a problem.
这篇关于使用 Java 字典...使用哈希表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!