Difference: equals() is a method defined in the Object class. It determines whether two objects are "equal" and is case-sensitive; equalsIgnoreCase is a method defined in the string class and is used to compare two strings. Whether the corresponding characters in are equal, case will be ignored.
##The difference between equals() and equalsIgnoreCase() in JAVA
1. Use the equals() method to compare whether two strings are equal. It has the following general form:
boolean equals(Object str)
2. In order to perform a case-ignoring comparison, you can call the equalsIgnoreCase() method.
When comparing two strings, it will think A-Z and a-z are the same. Its general form is as follows:boolean equalsIgnoreCase(String str)
// Demonstrate equals() and equalsIgnoreCase(). class equalsDemo { public static void main(String args[]) { String s1 = "Hello"; String s2 = "Hello"; String s3 = "Good-bye"; String s4 = "HELLO"; System.out.println(s1 + " equals " + s2 + " -> " + s1.equals(s2)); System.out.println(s1 + " equals " + s3 + " -> " + s1.equals(s3)); System.out.println(s1 + " equals " + s4 + " -> " + s1.equals(s4)); System.out.println(s1 + " equalsIgnoreCase " + s4 + " -> " + s1.equalsIgnoreCase(s4)); } }
Hello equals Hello -> true Hello equals Good-bye -> false Hello equals HELLO -> false Hello equalsIgnoreCase HELLO -> true
Programming Learning ! !
The above is the detailed content of What is the difference between equalsignorecase and equals?. For more information, please follow other related articles on the PHP Chinese website!