I have an arraylist of objects which contain multiple variables.
I generate new objects and want to conditionally check to see that an object with the same contents does not exist anyhwere in the arraylist.
Unfortunately both Arraylist.contains(object) and Arraylist.equals(object) only check for references of the same object, instead of objects with the same components. I want it to act like a much simpler String.contains(“x”) does.
How do I override arraylist.equals/arraylist.contains to do what I want within my android activity?
You can either create your own class that inherits from ArrayList and define your own definition for both.
Then replace your ArrayList types with MyArrayList types.
Or you could just make a method somewhere that accepts 2 ArrayLists and tells you if they are equal, or if one contains the other.