I am learning through w3schools. I am confused mainly about the meaning of java syntax. To my understanding, both functions the same except for the String cases.
The thing I don’t understand is their parameters; why is the other an Object and the other is String?
public boolean equals(Object anotherObject)
public boolean equalsIgnoreCase(String anotherString)
>Solution :
equals(Object) is defined in java.lang.Object and is a method that is available on all object in Java. Therefore it’s defined as generically as possible (i.e. it accepts any other object as the argument).
equalsIgnoreCase is only defined in java.lang.String. It’s a specific method for comparing strings in a specific way. Since it’s about text, it doesn’t make sense to accept any non-String object here.