Java 制作一个Hashmap,其键为字符串,值为HashSet
尝试使用字符串键和哈希集值创建哈希映射。我希望散列集都是整数Java 制作一个Hashmap,其键为字符串,值为HashSet,java,hashmap,hashset,Java,Hashmap,Hashset,尝试使用字符串键和哈希集值创建哈希映射。我希望散列集都是整数 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,
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
Set numberset=newhashset();
//不起作用:
HashMap数据库=新建HashMap()//错误-“(或[预期的”)
//也不起作用。如果它起作用了,我怎么能添加到这个hashMap内的集合中呢?
HashMap数据库=新HashMap();//错误不兼容类型
HashMap数据库=新建HashMap();
对我有用
顺便说一句,如果您使用的是JDK 1.7,那么您可以使用:
HashMap<String, HashSet<Integer>> mymap = new HashMap<>();
HashMap mymap=newhashmap();
HashMap数据库=新建HashMap();
对我有用
顺便说一句,如果您使用的是JDK 1.7,那么您可以使用:
HashMap<String, HashSet<Integer>> mymap = new HashMap<>();
HashMap mymap=newhashmap();
Map-mapOfSets=new-HashMap();Set-numberset=new-HashSet();mapOfSets.put(“numberset”,numberset);
,对我有效。路易吉,你应该回答这个问题。Map-mapOfSets=new-HashMap();Set-numberset=new-HashSet();mapOfSets.put(“numberset”,numberset);
,对我有效。路易吉,你应该回答这个问题。