Java String equals()The Java String class equals() method compares the two given strings based on the content of the string. If any character is not matched, it returns false. If all characters are matched, it returns true. The String equals() method overrides the equals() method of the Object class. SignatureParameteranotherObject : another object, i.e., compared with this string. Returnstrue if characters of both strings are equal otherwise false. Internal implementationJava String equals() Method ExampleFileName: EqualsExample.java Test it NowOutput: true false false Java String equals() Method Example 2The equals() method compares two strings and can be used in if-else control structure. FileName: EqualsExample2.java Output: true both strings are unequal Java String equals() Method Example 3Let's see one more example to test the equality of string present in the list. FileName: EqualsExample3.java Output: Mukesh is present Java String equals() Method Example 4The internal implementation of the equals() method shows that one can pass the reference of any object in the parameter of the method. The following example shows the same. FileName: EqualsExample4.java Output: false false false false true true true true Next TopicJava String equalsIgnoreCase() |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India