Search code examples
javaaemjcrmagnolia

Find a value for a specific key in a linked hashmap in java


Is there a simpler way to find a value for a specific key in a linked hash map in Java?

HashMap<String, Object> newmap = (HashMap<String, Object>) entry.getValue();
String newType = "";
//finds out the primaryType for the new node
for (Entry<String, Object> mapentry : newmap.entrySet()) {
    if (mapentry.getKey() == "jcr:primaryType") {
        newType = (String) newmap.get("jcr:primaryType");
    }
}

Solution

  • LinkedHashMap<String , Object> newmap = (LinkedHashMap<String, Object>) entry.getValue();
    String newType = (String) newmap.getOrDefault("jcr:primaryType", "");