in my android app, i would like to check, if a value is already in my array list.
i tried something like this:
private List<Values> retrieve() {
List<Values> list = new ArrayList<>();
int x = 0;
while (x < Values.length) {
if (list.contains(new Values(Values[x]))) {
Log.e("-->", "DUPLICATE: "+Values[x]);
} else {
Log.e("-->", "NEW: "+Values[x]);
list.add(new Values(Values[x]));
}
x++;
}
return list;
}
The content of my ArrayList "Values":
Max,Sabine,Chris,Max,Max
But i always get the Log "NEW". but this can't be right. The Value "Max" is an duplicate.
What is my mistake?