Java 循环遍历包含字符串和另一个映射的映射

Java 循环遍历包含字符串和另一个映射的映射,java,dictionary,foreach,hashmap,Java,Dictionary,Foreach,Hashmap,我声明我的地图如下: Map junctions=newhashmap() 并用数据填充: for (int i = 0; i < N; i++) { String[] coordinates = s.nextLine().split(" "); junctions.put(i, new HashMap<Integer, Integer>()); junctions.get(i).put(Integer.p

我声明我的地图如下:

Map junctions=newhashmap()

并用数据填充:

for (int i = 0; i < N; i++) {
            String[] coordinates = s.nextLine().split(" ");
            junctions.put(i, new HashMap<Integer, Integer>());
            junctions.get(i).put(Integer.parseInt(coordinates[0]), Integer.parseInt(coordinates[1]));
        } 
for(int i=0;i
但我无法打印出来,也无法使用它的内容

我试过这样做:

for (Map<Integer, Map<Integer, Integer>> m : junctions.entrySet()) {
            System.out.println(m.getKey() + "/" + m.getValue());
        }
for(映射m:junctions.entrySet()){
System.out.println(m.getKey()+“/”+m.getValue());
}
我还尝试使用
junctions.values()
而不是
junctions.entrySet()

我需要做什么?

应该是

for (Map.Entry<Integer, Map<Integer, Integer>> e : junctions.entrySet()) {
    System.out.println(e.getKey() + "/" + e.getValue());
}
for(Map.Entry e:junctions.entrySet()){
System.out.println(e.getKey()+“/”+e.getValue());
}

for(映射m:junctions.values()){
系统输出打印项次(m);
}

取决于您想要打印的内容。

您的示例代码看起来很像您可以用列表替换顶层的地图,因此e。g<代码>列表
。或者更好的方法,比如
List
for (Map<Integer, Integer> m : junctions.values()) {
    System.out.println(m);
}