2013-03-31 35 views
1

嘗試使用字符串鍵和HashSets的值生成Hash Map。我想哈希集是所有整數製作一個HashMap,其鍵值爲HashSets

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 
+3

'地圖<字符串,集> mapOfSets =新的HashMap <字符串,集>();設置 numbersSet = new HashSet (); mapOfSets.put(「numbersSet」,numbersSet);',適用於我。 –

+1

Luiggi,你應該做出答案。 – fish

回答

1
HashMap<String, HashSet<Integer>> database = new HashMap<String, HashSet<Integer>>(); 

爲我工作。

順便說一句,如果要使用JDK 1.7可以使用:

HashMap<String, HashSet<Integer>> mymap = new HashMap<>(); 
+0

非常感謝! – Sempiternal

相關問題