【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));
        }
    }
    。。。。。。
}
相关推荐
长友cy2 分钟前
Qt官方示例Application源码阅读
开发语言·qt
程序员良辰9 分钟前
服务器 JDK 环境变量配置:一键安装和手动配置有什么区别?
开发语言·python
奈斯先生Vector16 分钟前
本地图片识别怎么接入多模态 AI?用 Python API 理解 GPT-4o Vision 的真实工作流
开发语言·人工智能·windows·python·网络协议·http·aigc
OPEN-F20 分钟前
C++17新特性精讲:结构化绑定、if constexpr与实用类型
开发语言·c++
CoderYanger21 分钟前
A.每日一题:3345. 最小可整除数位乘积 I
java·数据结构·程序人生·算法·leetcode·面试·学习方法
OPEN-F23 分钟前
C++并发编程:线程与互斥锁
开发语言·c++
俊昭喜喜里25 分钟前
C#中的decimal
开发语言·c#
小刘是地理大王25 分钟前
OpenFeign 兜底回调(fallback / fallbackFactory)实战指南
java·后端
橘子汽水16829 分钟前
Leetcode15:三数之和
java·数据结构·算法