How to clone ArrayList and also clone its contents?

后端 未结 21 1951
小鲜肉
小鲜肉 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:16

    List dogs;
    List copiedDogs = dogs.stream().map(dog -> SerializationUtils.clone(dog)).Collectors.toList());
    

    This will deep copy each dog

提交回复
热议问题