How to clone ArrayList and also clone its contents?

后端 未结 21 1879
小鲜肉
小鲜肉 2020-11-21 06:42

How can I clone an ArrayList and also clone its items in Java?

For example I have:

ArrayList dogs = getDogs();
ArrayList

        
21条回答
  •  臣服心动
    2020-11-21 07:04

    Simple way is

    ArrayList dogs = getDogs();
    ArrayList clonedList = new ArrayList(dogs);
    

提交回复
热议问题