Java 创建一个hashmap,其键为integer,值为一组整数

Java 创建一个hashmap,其键为integer,值为一组整数,java,Java,我的任务是创建一个hashmap,其中包含整数键和类型为“hashset of integers”的值。目前,我尝试了以下方法: HashMap hm= new HashMap(Integer, new HashSet<>()); HashMap hm=newhashmap(整数,newhashset()); 我得到一个错误,告诉我找不到符号整数。非常感谢您的评论。以下是您应该如何申报地图: Map<Integer, HashSet<Integer>> h

我的任务是创建一个hashmap,其中包含整数键和类型为“hashset of integers”的值。目前,我尝试了以下方法:

HashMap hm= new HashMap(Integer, new HashSet<>());
HashMap hm=newhashmap(整数,newhashset());

我得到一个错误,告诉我找不到符号整数。非常感谢您的评论。

以下是您应该如何申报地图:

Map<Integer, HashSet<Integer>> hm = new HashMap<>(); // In Java SE 7, you can substitute the parameterized type of the constructor with an empty set of type parameters (<>)
Map<Integer, HashSet<Integer>> hm = new HashMap<Integer, HashSet<Integer>>(); // version of jdk prior to 7
Map hm=new HashMap();//在JavaSE7中,可以用一组空的类型参数()替换构造函数的参数化类型
Map hm=新HashMap();//jdk 7之前的版本

谢谢你的澄清,亚历克斯。