01:198:111 Lecture Notes - Lecture 24: Linear Search, Selection Sort, Insertion Sort
01:198:111 verified notes
24/28View all
Document Summary
Sequentially looking at the values of the list one after another. Depends on what is known about the list. In a list of ints or doubles, it"s easy, the == method is sufficient. Saying you"re trying to compare two robots objects in an array. Create an equal methods to do so. What do you want to compare to determine if it is. If it passes all these tests then return true. If (other == null || ! (other instanceof robot) { If (this. id== other. id && this. color. equals(other. color)){ return true; } The first if statement is to see if the object passed into the method is actually a robot object, if it is not then it must be not be equal. Robot other = (robot)other; here i am casting the passed into object as a robot object because if i do not then i will get an error in the program. This. color. equals(other. color) is done to see if two.