How to make a copy of ArrayList object which is type of List?

后端 未结 3 1872
日久生厌
日久生厌 2020-12-20 18:18

I studied Java is pass object reference by value, and in order to make a local copy of an object, I can either do clone() or copy-constructor. I also looked at deep/shallow

3条回答
  •  青春惊慌失措
    2020-12-20 19:11

    Passing the list into the constructor is probably the best way to go. The constructor invocation itself will use, behind the scenes, System.arraycopy. So it will effectively detach the local copy from the list passed in through the constructor.

提交回复
热议问题