如何获取Map <string,map <string,string>&gt;中存在的所有数据?数据结构?</string,map <string,string>

时间:2014-02-18 11:53:54

标签: java map

我想检索我的数据结构中存在的所有数据,这些数据的类型为Map of Map。数据结构如下所示。

public static Map<String, Map<String, String>> hourlyMap = new HashMap<String, Map<String, String>>();

我需要存储在地图中的所有数据而不管密钥。

3 个答案:

答案 0 :(得分:3)

这可能对您有所帮助

Map<String,Map<String,String>> hourlyMap = new HashMap<String,Map<String,String>>();
    for(Map<String,String> i:hourlyMap.values()){
        // now i is a Map<String,String>
        for(String str:i.values()){
            // now str is a value of map i
            System.out.println(str);
        }
    }

答案 1 :(得分:3)

尝试:

Set<String> allData = new HashSet<>();     // will contain all the values
for(Map<String, String> map : hourlyMap.values()) {
    allData.addAll(map.values());
}

答案 2 :(得分:1)

    for (String outerKey: hourlyMap.keySet()) {
        // outerKey holds the Key of the outer map
        // the value will be the inner map - hourlyMap.get(outerKey)

        System.out.println("Outer key: " + outerKey);
        for (String innerKey: hourlyMap.get(outerKey).keySet()) {

            // innerKey holds the Key of the inner map
            System.out.println("Inner key: " + innerKey);

            System.out.println("Inner value:" + hourlyMap.get(outerKey).get(innerKey));
        }

    }