【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));
        }
    }
    。。。。。。
}
相关推荐
麻瓜pro3 分钟前
【迭代】高性能c++实时对话系统e2e_voice
开发语言·c++·onnxruntime·端到端语音
zjxtxdy7 分钟前
C语言(续)
c语言·开发语言
无尽的沉默11 分钟前
Thymeleaf 基本语法和表达式
java·开发语言
Coder_Boy_18 分钟前
Java后端核心技术体系全解析(个人总结)
java·开发语言·spring boot·分布式·spring cloud·中间件
zh_xuan20 分钟前
kotlin Flow的用法2
android·开发语言·kotlin·协程·flow·被压
南部余额24 分钟前
函数式接口 Lambda 表达式好搭档:Predicate、Function、Consumer、Supplier
java·开发语言·consumer·lambda·function·predicate·supplier
遨游xyz36 分钟前
Trie树(字典树)
开发语言·python·mysql
Java后端的Ai之路36 分钟前
【JDK】-JDK 17 新特性整理(比较全)
java·开发语言·后端·jdk17
郝学胜-神的一滴37 分钟前
Effective Modern C++ 条款40:深入理解 Atomic 与 Volatile 的多线程语义
开发语言·c++·学习·算法·设计模式·架构
小小小米粒41 分钟前
Spring Boot Starter ,不止是 “打包好配置的工具类包”
java·开发语言