字典类 [英] Dictionary class
问题描述
可以在Java字典类中为单个键设置多个值。
Is it possible to have multiple values, for a single key, in the Java dictionary class?
推荐答案
字典类:该类被认为是obselete,文档建议使用Map代替。
First, regarding the dictionary class: That class is considered obselete, the documentation recommends using Map instead.
您正在寻找的这种集合称为多图。
你可以用一个列表实现一个,但是很繁琐。
This kind of collection you are seeking is called a multimap. You could implement one yourself with a list, but that is tedious.
你可以使用来自Apache Collections或者Google Collections的MultiMap。虽然我个人是apache集合的粉丝,他们不真正支持泛型,所以一个Google multimap可能会更安全。
You may want to use a MultiMap from either Apache Collections or from the Google Collections. While I am personally a fan of the apache collections, they do not really support generics, so a Google multimap may be safer.
这篇关于字典类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!