【发布时间】:2013-03-31 19:45:24
【问题描述】:
试图用字符串的键和 HashSet 的值创建一个 Hash Map。我希望哈希集都是整数
Set<String> numbersSet = new HashSet<Integer>();
// won't work:
HashMap<String, numberSet> database = new HashMap<String, numberSet>();//error - "( or [ expected"
//Also won't work. If it did, how can even I add to the set inside this hashMap?
HashMap<String, HashSet<Integer>> database = new HashMap<String, HashSet<Integer>>(); //error-incompatible types
【问题讨论】:
-
Map<String, Set<Integer>> mapOfSets = new HashMap<String, Set<Integer>>(); Set<Integer> numbersSet = new HashSet<Integer>(); mapOfSets.put("numbersSet", numbersSet);,为我工作。 -
Luiggi,你应该把它作为答案。