如何在java中创建哈希表的数组列表?
我想知道是否可以创建哈希表向量?
我尝试过
java.util.Hashtable<String, String>[] info = new java.util.Hashtable<String, String>();
,但没有运气:(
谢谢。
I would like to know if is it possible to create a vector of hashtables ?
i tried
java.util.Hashtable<String, String>[] info = new java.util.Hashtable<String, String>();
but haven't any luck :(
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我想你想要
I think you want
Vector
是一个List
,Hashtable
是一个Map
,所以你想要的是一个 Map 列表。我建议您分别使用
ArrayList
代替Vector
和HashMap
代替Hashtable
(如此处讨论和许多其他问题),但大多数全部我建议你改变你的要求。在大多数情况下,您需要一个列表地图而不是地图列表,如果您这样做,我会使用许多可用的自定义实现之一,首先也是最重要的 Guava 的
Multimap
。A
Vector
is aList
, and aHashtable
is aMap
, so what you want is a List of Maps.I'd advise you to use
ArrayList
instead ofVector
andHashMap
instead ofHashtable
, respectively (as discussed here and in many other questions), but most of all I'd advise you to change your requirements.In most cases, you'd want a Map of Lists rather than a List of Maps, and if you do, I'd use one of the many custom implementations available, first and foremost Guava's
Multimap
.您可能想要:
通过类型推断和 Guava 等库可以稍微简化这一点:
You probably want:
This can be simplified somewhat with type inference and a library such as Guava:
尝试确保您为正在使用的集合使用尽可能抽象的接口。
然后你可以添加你的哈希表
Try to make sure you are using as abstract an interface for the collections you are using as possible.
Then you can add your hashtables