以下是一个示例代码,实现了将fundPayList中第二个map中的"amount"字段修改为1000的功能。

import java.util.*;

public class Main {
    public static void main(String[] args) {
        // 初始化一个List<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", 500);
        fundPayList.add(map1);

        Map<String, Object> map2 = new HashMap<>();
        map2.put("id", 2);
        map2.put("name", "Jane");
        map2.put("amount", 800);
        fundPayList.add(map2);

        // 输出原始的fundPayList
        System.out.println("原始fundPayList:");
        for (Map<String, Object> map : fundPayList) {
            System.out.println(map);
        }

        // 修改fundPayList中第二个map中的"amount"字段为1000
        Map<String, Object> mapToModify = fundPayList.get(1);
        mapToModify.put("amount", 1000);

        // 输出修改后的fundPayList
        System.out.println("修改后的fundPayList:");
        for (Map<String, Object> map : fundPayList) {
            System.out.println(map);
        }
    }
}

输出结果如下:

原始fundPayList:
{id=1, name=John, amount=500}
{id=2, name=Jane, amount=800}
修改后的fundPayList:
{id=1, name=John, amount=500}
{id=2, name=Jane, amount=1000}
``
用java写一个修改指定ListMap fundPayList 中指定里面一个map里面的数据

原文地址: https://www.cveoy.top/t/topic/cvis 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录