I'm trying to copy each element from one ArrayList (av) to another one (copia). The thing is that they're copied by reference, so whenever I make any changes in the original one, the copy is modified as well. Of course, this behavior is not wanted. How should I write this method?
public void copiarArrayList(ArrayList<Articulo_Venta> copia, ArrayList<Articulo_Venta> av){
copia.clear();
for (int i = 0; i < av.size(); i++) {
copia.add(av.get(i));
}
}
Articulo_Venta has these fields:
int codigo;
String nombre;
float cantidad;
PS: I also tried the next:
copia = new ArrayList<Articulo_Venta>(av);
but it still has its elements pointing to the original ArrayList.