1. Use the Equals () method to compare two strings for equality (case-sensitive)
2. Use the Equalsignorecase () method to compare two strings for equality (case insensitive)
Boolean equalsignorecase (String str)
The following examples illustrate the Equals () and Equalsignorecase () methods:
Class Equalstest {
public static void Main (String args[]) {
String S1 = "Hello";
String s2 = "Hello";
String s3 = "HELLO";
SYSTEM.OUT.PRINTLN (S1 + "equals" + s2 + "+" + s1.equals (S2));
SYSTEM.OUT.PRINTLN (S1 + "equals" + s3 + "+" + s1.equals (S3));
SYSTEM.OUT.PRINTLN (S1 + "Equalsignorecase" + s3 + "+" + s1.equalsignorecase (S3));
}
}
The output of the program is as follows:
Hello equals Hello--True
Hello equals Hello--false
Hello equalsignorecase Hello--True
Differences between strings in Java compared to Equals () and Equalsignorecase ()