Java case-insensitive comparison
1. Java has provided a built-in case judgment Method: equalsIgnoreCase().
Usage: (Recommended tutorial: java tutorial)
"ABC".equalsIgnoreCase("abc"); // 将字符串ABC与abc忽略大小写进行比较
2. Use toLowerCase() Compare with contains
Convert both strings to lowercase for comparison
s1.toLowerCase().contains(s2.toLowerCase());
Extension:
equalsIgnoreCase and The difference between equals
String.equals() is case-sensitive, while String.equalsIgnoreCase() ignores case
For example:
"ABC".equals ("abc") is false
"ABC".equalsIgnoreCase("abc") is true
The above is the detailed content of Java case insensitive comparison. For more information, please follow other related articles on the PHP Chinese website!