I have two ArrayList objects (using Java), each object with several attributes of different type. I would like to know if these two ArrayList contain the same objects (neither more nor less), with the same values. The order is indifferent.
I have the following code:
ArrayList<Producto>productoRec=new ArrayList<(Producto.recuperarArray());
for(Producto e : productoRec){
if(e!=null){
System.out.println(e);
}
}
for(Producto e : producto){
if(e!=null){
System.out.println(e);
}
}
if(producto.equals(productoRec)){
ES.msgln("Los ArrayList son iguales.");
}else{
ES.msgln("Los ArrayList son diferentes.");
}
When I run I get:
Fruit: Product code: 3 Product name: n (not seasonal fruit)
Fruit: Product code: 3 Product name: n (not seasonal fruit)
The ArrayList are different. BUILD SUCCESSFUL (total time: 3 seconds)
I do not know what I am doing wrong, but it is clear that the ArrayList are the same, but nevertheless the answer when executing it is that they are different.