是否有更简单的方法来在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");
}
}
由于默认结果为""
,所以可以这样做
String newType = newmap.getOrDefault("jcr:primaryType", "");
LinkedHashMap<String , Object> newmap = (LinkedHashMap<String, Object>) entry.getValue();
String newType = (String) newmap.getOrDefault("jcr:primaryType", "");