why equals() method when we have == operator? [duplicate]
问题 This question already has answers here : How do I compare strings in Java? (23 answers) Closed 6 years ago . When i see the implementation of equals() method it does nothing but same as what == does. So my question is what was the need to have this as separate method when we have == operator which does the same work? 回答1: You can not overload the == operator, but you can override equals(Object) if you want it to behave differently from the == operator, i.e. not compare references but actually