Let's say I have an Object called Index
, this object has two attributes Long id; , String name;
and I have two ArrayLists
in my page, the problem is that when I edit the name of the index object in the first list it is being edited in the second list as well, here is my code to make the problem more understandable:
Index index1 = new Index();
index1.setName("1");
index1.setId(1);
List<Index> indexes = new ArrayList<Index>();
indexes.add(index1);
List<Index> newIndexes = new ArrayList<Index>();
newIndexes.add(index1);
Now if I update the name of the index in the indexes
list it is being updated in the newIndexes
list. note: the object index has equals method on the Id
field.
Thanks