The solution assumes that you're already familiar with the equals method.
And to the equals method must return false if the parameters no.
So if object is equal to No.
Return false.
It needs to return false if the parameter is not an instance of item, so if object.
Is not an instance of item.
Return false.
Otherwise, at this point, we can typecast the parameter to the type item.
And now we can compare every field from both objects.
Return this thought name.
Equals item name.
And we'll return the bullying result from this stock price equalling item price.
All right, now contains is going to compare every item object inside the array list against the parameter
using the new equals method.
If that's true, then our coach would finally work.
And beautiful, it recognizes that the items list already contains the salary object and it didn't add
it.
For the sake of visualizing the runtime, I'll add a few break points and launch the debugger.
At first, the list doesn't contain anything, so we can just step over it.
And add the first item.
OK, now the area list already contains the celery object, let's see if this works, I'm going to step
into contains it should run the equals method for the first element.
Watch and see that it runs the equals method for the item object.
The parameter that we're comparing against is not No.
It is an object of the atom class.
The fields between those two objects are equal.
So the equals method is going to return, true.
So the aerialists does contain the object.
And because the array list already contains this object, we're just going to break the function by
returning false and that is all.