1 00:00:01,859 --> 00:00:04,920 The solution assumes that you're already familiar with the equals method. 2 00:00:21,690 --> 00:00:25,230 And to the equals method must return false if the parameters no. 3 00:00:25,500 --> 00:00:27,510 So if object is equal to No. 4 00:00:32,310 --> 00:00:33,450 Return false. 5 00:00:37,400 --> 00:00:42,470 It needs to return false if the parameter is not an instance of item, so if object. 6 00:00:44,350 --> 00:00:46,150 Is not an instance of item. 7 00:00:50,150 --> 00:00:51,290 Return false. 8 00:00:55,810 --> 00:01:00,100 Otherwise, at this point, we can typecast the parameter to the type item. 9 00:01:05,830 --> 00:01:08,710 And now we can compare every field from both objects. 10 00:01:10,160 --> 00:01:11,540 Return this thought name. 11 00:01:13,620 --> 00:01:15,030 Equals item name. 12 00:01:21,140 --> 00:01:26,150 And we'll return the bullying result from this stock price equalling item price. 13 00:01:31,190 --> 00:01:36,890 All right, now contains is going to compare every item object inside the array list against the parameter 14 00:01:36,890 --> 00:01:38,510 using the new equals method. 15 00:01:39,000 --> 00:01:41,540 If that's true, then our coach would finally work. 16 00:01:52,870 --> 00:01:58,810 And beautiful, it recognizes that the items list already contains the salary object and it didn't add 17 00:01:58,810 --> 00:01:58,930 it. 18 00:02:00,220 --> 00:02:04,780 For the sake of visualizing the runtime, I'll add a few break points and launch the debugger. 19 00:02:22,590 --> 00:02:25,980 At first, the list doesn't contain anything, so we can just step over it. 20 00:02:30,230 --> 00:02:31,550 And add the first item. 21 00:02:35,120 --> 00:02:41,420 OK, now the area list already contains the celery object, let's see if this works, I'm going to step 22 00:02:41,420 --> 00:02:45,380 into contains it should run the equals method for the first element. 23 00:02:49,510 --> 00:02:53,700 Watch and see that it runs the equals method for the item object. 24 00:03:04,560 --> 00:03:07,260 The parameter that we're comparing against is not No. 25 00:03:10,430 --> 00:03:12,320 It is an object of the atom class. 26 00:03:17,290 --> 00:03:19,990 The fields between those two objects are equal. 27 00:03:24,090 --> 00:03:26,250 So the equals method is going to return, true. 28 00:03:34,500 --> 00:03:37,050 So the aerialists does contain the object. 29 00:03:40,260 --> 00:03:45,450 And because the array list already contains this object, we're just going to break the function by 30 00:03:45,450 --> 00:03:47,610 returning false and that is all.