【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));
        }
    }
    。。。。。。
}
相关推荐
Raas1004 小时前
AI网关和OpenRouter区别?MAI Gateway(魔芋企业级AI网关)企业级方案对比指南
大数据·开发语言·人工智能·gateway·php·ai网关·mai gateway
点心的游戏开发世界12 小时前
GDScript 入门笔记(十一):Lambda 与匿名函数
开发语言·笔记·游戏引擎·godot
phltxy12 小时前
C语言操作符详解
java·c语言·算法
步行cgn13 小时前
@Configuration 详解:Spring 配置类的核心注解
java·后端·spring
sunshine22 girl13 小时前
Java学习一 环境配置2 安装和基本使用Idea
java·学习·intellij-idea
事圆则缓14 小时前
Kotlin 协程完全指南
开发语言·kotlin
我爱写代码i14 小时前
BeLink - 支持生成多种URL 缩短网址PHP源码
开发语言·php·短网址php源码
Java后端的Ai之路14 小时前
20、Python - 备忘录模式
开发语言·人工智能·python·外观模式·备忘录模式
嘿嘿-6615 小时前
Windows 一键使用 GPT-6 Astra:Codex CLI 配置教程
java·人工智能·windows·gpt·chatgpt·web
统计学小王子15 小时前
数学建模国赛倒计时4天——《统计模型精讲(混合效应模型R语言实现)》
开发语言·数学建模·r语言