【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));
        }
    }
    。。。。。。
}
相关推荐
bagadesu1 小时前
使用Docker构建Node.js应用的详细指南
java·后端
没有bug.的程序员1 小时前
Spring Cloud Gateway 性能优化与限流设计
java·spring boot·spring·nacos·性能优化·gateway·springcloud
molunnnn1 小时前
第四章 Agent的几种经典范式
开发语言·python
洛_尘2 小时前
JAVA EE初阶 2: 多线程-初阶
java·开发语言
Slow菜鸟2 小时前
Java 开发环境安装指南(五) | Git 安装
java·git
@卞3 小时前
C语言常见概念
c语言·开发语言
wjs20243 小时前
Eclipse 关闭项目详解
开发语言
沐知全栈开发3 小时前
《隐藏(Hide)》
开发语言
lkbhua莱克瓦243 小时前
Java基础——方法
java·开发语言·笔记·github·学习方法