Why does String define the equals( ) method? - Java

Why does String define the equals( ) method? Can’t I just use ==?

The equals() method is defined in String class in order to test whether two strings values are same sequence of characters. The method is for exclusively testing string objects, but not any other objects.

The operator ‘==’ always compares the variables but not objects. The ‘reference variables’ are compared with ‘==’, but not the objects. In terms of strings, the ‘==’ operator always compares the references and not the ‘character sequences’.
String objects are immutable in java
A string object that is created using “String” class is immutable. The characters of the object can not be changed / modified. There are some methods, such as split(), substring(), beginsWith() etc...
Can we pass a primitive type by reference in java? - Java
Primitive types can be passed by reference. 1. By storing the primitive type value in an array of single element and passing it...
What do you mean by the term signature in java?
A signature in java is a combination of elements in a list such as constructor and methods thereby distinguishing them from other constructors and methods...
Post your comment