【JAVA:list中再定义一个list对象,循环赋值不同的list数据,出现追加重复数据问题】

问题描述:

list中再定义一个list对象,循环赋值不同的list数据,结果全部都累加到每条数据中了,每条数据中都出现重复数据。

问题解决:

1.创建树结构方法信息

2.创建一个新的 List 对象,避免引用问题

3.使用 GongkuangMethodDictVo 的拷贝构造函数

java 复制代码
public class PlanSchemeProductionGongkuangStatus
{
	。。。。。。
    /** 创建树结构方法信息 */
    private List<GongkuangMethodDictVo> gongkuangMethodDicList;

    public List<GongkuangMethodDictVo> getGongkuangMethodDicList() {
        return gongkuangMethodDicList;
    }

    public void setGongkuangMethodDicList(List<GongkuangMethodDictVo> gongkuangMethodDicList) {
        // 创建一个新的 List 对象,避免引用问题
        this.gongkuangMethodDicList = new ArrayList<>();
        for (GongkuangMethodDictVo gongkuangMethodDictVo : gongkuangMethodDicList) {
            // 使用 GongkuangMethodDictVo 的拷贝构造函数
            this.gongkuangMethodDicList.add(new GongkuangMethodDictVo(gongkuangMethodDictVo));
        }
    }
    。。。。。。
}
相关推荐
cnxy1882 小时前
围棋对弈Python程序开发完整指南:步骤1 - 棋盘基础框架搭建
开发语言·python
Nonoas3 小时前
动态代理:发布订阅的高级玩法
java·ide·intellij-idea
程序员-周李斌3 小时前
Java 死锁
java·开发语言·后端
皮皮林5514 小时前
Prometheus+Grafana,打造强大的监控与可视化平台
java
JasmineWr4 小时前
CompletableFuture相关问题
java·开发语言
零雲4 小时前
java面试:知道java的反射机制吗
java·开发语言·面试
Jeremy爱编码4 小时前
实现 Trie (前缀树)
开发语言·c#
laocooon5238578864 小时前
插入法排序 python
开发语言·python·算法
你的冰西瓜5 小时前
C++中的list容器详解
开发语言·c++·stl·list
java1234_小锋5 小时前
Java进程占用的内存有哪些部分?
java