我的输入中只有一个列表,共13个HashMap。每个HashMap仅具有2个键“ fieldName”和“ accessibilityType”以及相应的值:"fieldAccessibility": [ { "fieldName": "firstName", "accessibilityType": "EDITABLE" }, { "fieldName": "lastName", "accessibilityType": "EDITABLE" }, { "fieldName": "avatarUrl", "accessibilityType": "EDITABLE" }, { "fieldName": "username", "accessibilityType": "EDITABLE" }, { "fieldName": "birthDate", "accessibilityType": "EDITABLE" }, { "fieldName": "phoneNumbers", "accessibilityType": "EDITABLE" }, { "fieldName": "email", "accessibilityType": "EDITABLE" }, { "fieldName": "language", "accessibilityType": "EDITABLE" }, { "fieldName": "externalId", "accessibilityType": "EDITABLE" }, { "fieldName": "externalCode", "accessibilityType": "EDITABLE" }, { "fieldName": "punchBadgeId", "accessibilityType": "EDITABLE" }, { "fieldName": "minor", "accessibilityType": "EDITABLE" }, { "fieldName": "seniorityDate", "accessibilityType": "EDITABLE" }]我试图通过它进行迭代,并将“ accessibilityType”的值更改为“ READ”,其中“ fieldName”是“ birthDate”。有人可以说一种有效的方法来做到这一点。到目前为止,这是我尝试读取和打印每个键值对的尝试:final List<HashMap<String, String>> list = some code to get the input; for (HashMap<String, String> m : list) { for (HashMap.Entry<String, String> e : m.entrySet()) { String key = e.getKey(); String value = e.getValue(); System.out.println("SEE HERE TEST " + key + " = " + value); }}
2 回答
蝴蝶刀刀
TA贡献1801条经验 获得超8个赞
forEach从JDK-8开始,可以通过以下方式完成此操作:
list.forEach(map -> {
String fieldName = map.get("fieldName");
if("birthDate".equals(fieldName)) map.put("accessibilityType", "READ");
});
添加回答
举报
0/150
提交
取消