[Solved] How to iterate complicated List of Maps containing Maps


How about this?

    ArrayList<HashMap<String, HashMap<String, String>>> list = new ArrayList<>();

    for (HashMap<String, HashMap<String, String>> m : list) {
        for (Map.Entry<String, HashMap<String, String>> e : m.entrySet()) {
            String key1 = e.getKey();
            for (Map.Entry<String, String> me : e.getValue().entrySet()) {
                String key2 = me.getKey();
                String value = me.getValue();
            }
        }
    }

Note that you really should be using the interface form of the objects:

    List<Map<String, Map<String, String>>> list = new ArrayList<>();

    for (Map<String, Map<String, String>> m : list) {
        // All Maps.
        for (Map.Entry<String, Map<String, String>> e : m.entrySet()) {
            // Outer key.
            String key1 = e.getKey();
            for (Map.Entry<String, String> me : e.getValue().entrySet()) {
                // Inner key.
                String key2 = me.getKey();
                // The String value.
                String value = me.getValue();
            }
        }
    }

0

solved How to iterate complicated List of Maps containing Maps