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...