用java不通过index来修改ListMap fundPayList 中指定里面一个map里面的数据
可以通过Map的key来获取指定的Map对象,然后对其进行修改,示例代码如下:
List<Map<String, Object>> fundPayList = new ArrayList<>();
// 添加一些示例数据
Map<String, Object> map1 = new HashMap<>();
map1.put("id", 1);
map1.put("name", "John");
map1.put("amount", 100);
fundPayList.add(map1);
Map<String, Object> map2 = new HashMap<>();
map2.put("id", 2);
map2.put("name", "Jane");
map2.put("amount", 200);
fundPayList.add(map2);
// 获取指定的Map对象并修改其数据
for (Map<String, Object> map : fundPayList) {
if (map.get("id").equals(1)) {
map.put("amount", 150);
break;
}
}
// 输出修改后的结果
for (Map<String, Object> map : fundPayList) {
System.out.println(map);
}
上述代码中,通过遍历List中的每一个Map对象,通过比较Map中的id属性是否等于指定的值,找到需要修改的Map对象。然后通过put方法修改该Map对象中指定的属性值。最后再遍历一遍List输出修改后的结果
原文地址: https://www.cveoy.top/t/topic/cviU 著作权归作者所有。请勿转载和采集!