# Copying ArrayLists without affecting original

**URL:** <https://discourse.processing.org/t/copying-arraylists-without-affecting-original/24820>\
**Category:** Coding Questions\
**Created:** [October 22, 2020, 1:25pm UTC](https://discourse.processing.org/t/copying-arraylists-without-affecting-original/24820 "2020-10-22T13:25:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![arcadeperfect](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@arcadeperfect](https://discourse.processing.org/u/arcadeperfect)\
**Post date:** [October 22, 2020, 1:25pm UTC](https://discourse.processing.org/t/copying-arraylists-without-affecting-original/24820/1 "2020-10-22T13:25:08Z")

</div>

Hi,

Is there a way to create a new copy of an ArrayList full of custom classes (in case it’s relevant), such that modifications to the objects in the new list will not affect the originals?

Failing that, is there a way to copy an object short of explicitly writing a copy method that instantiates a new object with the same parameters?

Thanks!

---

<div class="post-metadata">

**Author:** ![micycle](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micycle/32/201_2.png) [@micycle](https://discourse.processing.org/u/micycle)\
**Post date:** [October 22, 2020, 1:30pm UTC](https://discourse.processing.org/t/copying-arraylists-without-affecting-original/24820/2 "2020-10-22T13:30:29Z")

</div>

> **[ArrayList clone() - Deep copy and shallow copy - HowToDoInJava](https://howtodoinjava.com/java/collections/arraylist/arraylist-clone-deep-copy/)**
>
> ArrayList clone() method is used to create a shallow copy of the list. Learn to create deep copy and shallow copy of an arraylist with example.

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [October 22, 2020, 1:37pm UTC](https://discourse.processing.org/t/copying-arraylists-without-affecting-original/24820/3 "2020-10-22T13:37:10Z")

</div>

> [@Functions argument](https://discourse.processing.org/t/functions-argument/11010/5):
>
> Or even better, use it as an actual full-fledged class, w/ constructors, fields & methods: triumph // https://Discourse.Processing.org/t/functions-argument/11010/5 // GoToLoop (v1.1) (2019/May/09) final Pair pair = new Pair(5, -10); void setup() { println(pair); // [5, -10] println(pair.calc('y')); // [-50, 540] println(pair.set(5, -10)); // [5, -10] println(pair.calc('u')); // [3, -2] println(pair.clone()); // [3, -2] exit(); } static final class…

> [@Problema con Class, extend y herencia](https://discourse.processing.org/t/problema-con-class-extend-y-herencia/11204/2):
>
> Disclaimer: I know English & Portuguese only. expressionless And although I can understand Spanish more or less, still I can’t properly reply using it, sorry. disappointed Anyways, we can always count on Google Translate, right? relieved[https://Translate.Google.com/#view=home&op=translate&sl=en&tl=es](https://Translate.Google.com/#view=home&op=translate&sl=en&tl=es) Indeed, if your method Animal::hijo() is something like this: class Animal { Animal hijo(final String name) { return new Animal(name); } } And you’ve got a class that extends i…
