How to backup ArrayList in Java?

后端 未结 10 1486
刺人心
刺人心 2020-12-09 12:40

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 ArrayL

10条回答
  •  庸人自扰
    2020-12-09 12:51

    It sounds (if I interpret your question properly; it's a little tough) like you're not copying the data that you're referring to in your ArrayList to your backup; you're copying the reference.

    It's hard to say exactly how to solve your problem without knowing what your data type is that you're storing / backing up, but just be sure that you're copying the elements of the data contained within the ArrayList. That would mean, among other things, to do things like perform a clone() on the elements of the list, but not on the ArrayList (because that'll create a new cloned list with copies of the references to the same objects).

提交回复
热议问题