【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));
        }
    }
    。。。。。。
}
相关推荐
Lzh编程小栈1 分钟前
数据结构与算法——单链表超详解(C语言完整实现 + 面试高频题)
c语言·开发语言·面试
沐知全栈开发2 分钟前
Shell 函数
开发语言
2301_816651223 分钟前
移动语义在容器中的应用
开发语言·c++·算法
稻草猫.5 分钟前
MyBatis进阶:动态SQL与MyBatis Generator插件使用
java·数据库·后端·spring·mvc·mybatis
2401_857918295 分钟前
实时数据处理中的C++应用
开发语言·c++·算法
2401_884563246 分钟前
C++中的装饰器模式实战
开发语言·c++·算法
xiangpanf6 分钟前
PHP vs Go:30秒读懂核心差异
java·开发语言
爱喝一杯白开水6 分钟前
Java List 常用方法全攻略
java·list·排序算法
聆风吟º7 分钟前
【C标准库】C语言memset函数详解:从原理到实战避坑
c语言·开发语言·库函数·memset
idealzouhu8 分钟前
【Kotlin】 数据流完全指南:冷流、热流与 Android 实战
android·开发语言·kotlin