Reputation: 127
Trying to make a Hash Map with keys of strings, and values of HashSets. I want the hash sets to be all integers
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
Upvotes: 1
Views: 2221
Reputation: 4973
HashMap<String, HashSet<Integer>> database = new HashMap<String, HashSet<Integer>>();
Works for me.
BTW, if you are using JDK 1.7 you can use:
HashMap<String, HashSet<Integer>> mymap = new HashMap<>();
Upvotes: 1