[Solved] How to retrieve an element inside a Map in Java?


Your ENUM values on the map seem like another map. Therefore I put it like this

Map<Enum, Map<String, Object>>

However, question is not clear! Here is one possible solution.

import java.util.*;    
public class Main {

    public static void main(String[] args) {

        Map<Enum, Map<String, Object>> map = new HashMap<>();
        Map<String, Object> value = new HashMap<>();
        value.put("String1", "Something written here");
        value.put("check", true);
        value.put("String2", "Something written here");
        map.put(Enum.ENUM1, value);
        value = new HashMap<>();
        value.put("String1", "Something written here");
        value.put("check", true);
        value.put("String2", "Something written here");
        map.put(Enum.ENUM2, value);

        //string1 Object always will be String
        String result;
        for (Map.Entry<String,Object> entry :  map.get(Enum.ENUM1).entrySet()) {
            if (entry.getKey().equals("string1")) {
                result = entry.getValue().toString();
            }
        }

    }
}

enum Enum {
    ENUM1,
    ENUM2
}

solved How to retrieve an element inside a Map<> in Java?