如何在 Java 中备份 ArrayList? [英] How to backup ArrayList in Java?
本文介绍了如何在 Java 中备份 ArrayList?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将一些数据存储为 ArrayList
.当我想备份这些数据时,java 永远绑定了两个对象.这意味着当我更改数据 ArrayList
中的值时,此更改会备份.我尝试将数据中的值分别复制到循环中的备份,尝试使用方法 data.clone()
— 没有任何帮助.
I have some data stored as ArrayList
. And when I want to backup this data,java bounds two objects forever. Which means when I change values in data ArrayList
this changes come to backup. I tried to copy values from data separately to backup in the loop, tried to use method data.clone()
— nothing helps.
推荐答案
我认为您需要 .clone()
单个对象.克隆 ArrayList
并不深";它只会克隆对对象的引用.
I think you need to .clone()
the individual objects. Cloning the ArrayList
is not "deep"; it will only clone the references to the object.
这篇关于如何在 Java 中备份 ArrayList?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文