Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/366.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 制作一个Hashmap,其键为字符串,值为HashSet_Java_Hashmap_Hashset - Fatal编程技术网

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);
,对我有效。路易吉,你应该回答这个问题。