I use ArrayList , and at some point in the program, I use the contains method to check for the presence of a specific element in an ArrayList . An ArrayList stores objects of type CharProfile , a custom class, and it sees that it contains char.
So I use the equals method in the contains method. So something like CharProfile.contains(char) , but it does not work.
I override the equals method in CharProfile:
@Override public boolean equals(Object o) { if (this.character == (Character)o) { return true; } else { return false; } }
So, it should use my equals method when CharProfile tries to use it, right? So why doesn't it work?
(In terms of βnot working,β I mean the fact that contains always returns false.)
source share