Java 将单个集合作为映射的值进行访问

Java 将单个集合作为映射的值进行访问,java,collections,syntax,map,Java,Collections,Syntax,Map,当值为集合时,我需要显示映射的键值对中的值。可以将显示值的键指定为方法的参数。我不确定访问这个的语法是什么。当它是一个字符串时,我成功地完成了它 任何人都可以提出以下建议: HashMap<String, Set<Integer>> map = new HashMap<>(); Set<Integer> theValues = new Set<>(); public void mapValue(String aString) {

当值为集合时,我需要显示映射的键值对中的值。可以将显示值的键指定为方法的参数。我不确定访问这个的语法是什么。当它是一个字符串时,我成功地完成了它

任何人都可以提出以下建议:

HashMap<String, Set<Integer>> map = new HashMap<>();
Set<Integer> theValues = new Set<>();

public void mapValue(String aString)
{
    if(map.containsKey(aString))
    { 

      System.out.println ("The value of the set is " + theValues  ); 
      // what can go here to show the elements of the set that 
      // is the value map given the key?
    }


}
HashMap map=newhashmap();
设置值=新设置();
公共void映射值(字符串aString)
{
if(地图集装箱箱(aString))
{ 
System.out.println(“集合的值为”+值);
//这里可以显示哪些元素
//是否为值映射提供了键?
}
}

您可能需要这样的东西来迭代每个映射键的设置值:

HashMap<String, Set<Integer>> map = new HashMap<String,Set<Integer>>();
Set<Integer> theValues = new HashSet<Integer>();

public void mapValue(String aString) {
    if(map.containsKey(aString)) {
        System.out.println ("The values of the set is:");
        Set<Integer> set = map.get(aString);
        for (Integer i: set)
            System.out.println(i);
    }
}
HashMap map=newhashmap();
Set theValues=newhashset();
公共void映射值(字符串aString){
if(地图集装箱箱(aString)){
System.out.println(“集合的值为:”);
Set=map.get(aString);
for(整数i:set)
系统输出打印LN(i);
}
}

是否需要对给定的键进行整组设置?
map.get(aString)
返回与键关联的值。在这种情况下,该值是一个