why equals() method when we have == operator? [duplicate]
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 compare the objects (e.g. using all or some of their fields). Also, if you do override equals(Object), have a look at hashCode() as well. These two … Read more