Trying to look through array and want it to return true if name is in the array and false if it isn't.
public boolean ifInArray(String name)
{
for ( Dog breed: breeds) {
if (breed.equals(name)) {
return true;
} else {
return false;
}
}
}
true.breedis of typeDog, andnameis of typeString, so the two should never be equal. If you're writtenDog.equalssuch that it returnstruewhen given a String (for instance, if the String represents the same breed), then that's incorrect. The contract forequalsrequires that it's symmetric -- that ifa.equals(b)thenb.equals(a). Since you have no control overString.equals(and in particular, can never make it returntruewhen given aDog), you should never haveDog.equalsreturntruewhen given aString.