欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 汽车 > 时评 > 【JAVA:list中再定义一个list对象,循环赋值不同的list数据,出现追加重复数据问题】

【JAVA:list中再定义一个list对象,循环赋值不同的list数据,出现追加重复数据问题】

2025/2/22 12:20:13 来源:https://blog.csdn.net/yinchoushi8780/article/details/145734259  浏览:    关键词:【JAVA:list中再定义一个list对象,循环赋值不同的list数据,出现追加重复数据问题】

问题描述:

list中再定义一个list对象,循环赋值不同的list数据,结果全部都累加到每条数据中了,每条数据中都出现重复数据。

问题解决:

1.创建树结构方法信息
2.创建一个新的 List 对象,避免引用问题
3.使用 GongkuangMethodDictVo 的拷贝构造函数

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));}}。。。。。。
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词