尝试使用字符串键和哈希集值创建 HashMap 。我希望哈希集都是整数
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
最佳答案
HashMap<String, HashSet<Integer>> database = new HashMap<String, HashSet<Integer>>();
对我有用。
顺便说一句,如果您使用的是 JDK 1.7,您可以使用:
HashMap<String, HashSet<Integer>> mymap = new HashMap<>();
关于java - 制作一个 Hashmap,其键是字符串,值是 HashSets,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15733733/