Case insensitive list Java
Ngày đăng:
24/01/2022
Trả lời:
0
Lượt xem:
196
Java String equalsIgnoreCase() method is used to compare a string with the method argument object, ignoring case considerations. Show In equalsIgnoreCase() method, two strings are considered equal if they are of the same length and corresponding characters in the two strings are equal ignoring case. 1. Java String equalsIgnoreCase() method/** * @param anObject - The object to compare * @return true - if the non-null argument string represents the same sequence of characters to this string * false - in all other cases */ public boolean equalsIgnoreCase(String anotherString) { return (this == anotherString) ? true : (anotherString != null) && (anotherString.value.length == value.length) && regionMatches(true, 0, anotherString, 0, value.length); }
2. Java String equalsIgnoreCase() exampleJava program to check if two strings are equal (case-insensitive). Notice that equals() and equalsIgnoreCase() methods behave in same way, except later is case-insensitive. public static void main(String[] args) { String blogName = "howtodoinjava.com"; String authorName = "Lokesh gupta"; //1 - case-insensitive comparison isEqualString = blogName.equalsIgnoreCase("HOWTODOINJAVA.COM"); //true //2 - case-insensitive comparison isEqualString = blogName.equalsIgnoreCase("howtodoinjava.com"); //true //3 - check two strings for same character sequence ignoring case boolean isEqualString = blogName.equalsIgnoreCase(authorName); //false //4 - null is allowed isEqualString = blogName.equalsIgnoreCase(null); //false } }3. Java String equals() exampleJava program to check if two strings are equal (case-sensitive) using equals() method. 4. Difference between equals and equalsIgnoreCaseClearly, the difference between equals and equalsIgnoreCase in Java is case-sensitity while performing the string comparisons.
Happy Learning !! Reference: String Java Doc Was this post helpful?Let us know if you liked the post. Thats the only way we can improve. Yes No Further Reading:Java String equals() method Java compare strings Java String compareToIgnoreCase() method example Jersey Case-insensitive @Path URLs |