I have array list in java:
List<Correction> Auv=new ArrayList<>();
List<Correction> Produv=new ArrayList<>();
then I want to substract Produv value by Auv, here's an example:
Produv.add(new Correction("a","b"));
Produv.add(new Correction("a","c"));
Produv.add(new Correction("b","d"));
Produv.add(new Correction("b","c"));
Auv.add(new Correction("c","a"));
Auv.add(new Correction("b","c"));
Produv.removeall(Auv);
but nothing subtracted, the array still contain it initial value, is there any way to do this? I try to override equals(), and still got the same result
here the code of my Correction class:
public class Correction {
private String node0;
private String node1;
public Correction(String node0, String node1) {
this.node0 = node0;
this.node1 = node1;
}
public void setNode0(String node0){
this.node0=node0;
}
public void setNode1(String node1){
this.node1=node1;
}
public String getNode0(){
return node0;
}
public String getNode1(){
return node1;
}
@Override
public boolean equals(Object object){
boolean same = false;
if (object != null && object instanceof Correction)
{
same = this.node0 == ((Correction) object).node1 && this.node1 == ((Correction) object).node1;
}
return same;
}
}
Solved!! it just simply a mistake on overriding equals() method(thank's guys) here my correction:
@Override
public boolean equals(Object object){
boolean same = false;
if (object != null && object instanceof Correction)
{
same = (this.node0 == ((Correction) object).node1 && this.node1 == ((Correction) object).node0)||(this.node0 == ((Correction) object).node0 && this.node1 == ((Correction) object).node1);
}
return same;
}