I have two ArrayLists,
ArrayList<Item> array1 = new ArrayList<>();
// and
ArrayList<Item> array2 = new ArrayList<>();
in Item class I also have default boolean check = false;
I do checking, before everything I clean array2.clear()
and required one from array1 add to array2:
array2.clear();
for (Item i : array1) {
if (.....) {
array2.add(i);
}
}
If in array2 boolean check
is changed from false
to true
it is also changed in array1. How do I keep them separate so next time I add elements to array2 boolean check wouldn't copy as true
?