Try to run the following code, I have modified it and added Logs, now u can check output printed on the console:
I would suggest you check for the object by using equals().
class MyModel {
private int value;
public int getValue() {
return value;
}
public void setValue(int value) {
this.value = value;
}
@Override
public String toString() {
return "MyModel{" +
"value=" + value +
'}';
}
}
final List<MyModel> listModel = new ArrayList<>();
MyModel myModel;
myModel= new MyModel();
myModel.setValue(1);
myModel.setValue(2);
myModel.setValue(3);
listModel.add(myModel);
//here your myModel object has '3' value and list has [3], So this will return `true`
System.out.println("myModel=>"+myModel.toString()+"-->List = "+listModel.toString()+",, CONTAINS. =>"+listModel.contains(myModel));
myModel= new MyModel();
myModel.setValue(8);
listModel.add(myModel);
//here your myModel object has '8' value and list has [3,8], So this will return `true`
System.out.println("myModel=>"+myModel.toString()+"-->List = "+listModel.toString()+",, CONTAINS. =>"+listModel.contains(myModel));
myModel= new MyModel();
myModel.setValue(100);
//here your myModel object has '100' value and list has [3,8], So this will return `false`
System.out.println("myModel=>"+myModel.toString()+"-->List = "+listModel.toString()+",, CONTAINS. =>"+listModel.contains(myModel));