Java 程序用于忽略大小写来检查两字符串之间的等式
在 Java 中使用 equalsIgnoreCase() 忽略大小写来检查两个字符串之间的等式。
假设以下内容是我们的两个字符串。
String one = "rocky"; String two = "Rocky";
这两个字符串相等,但大小写不同。由于此方法忽略大小写,因此这两个字符串都被视为相等。
在此处,我们检查的是同一问题。
if(one.equalsIgnoreCase(two)) { System.out.println("String one is equal to two (ignoring the case) i.e. one==two"); }else{ System.out.println("String one is not equal to String two (ignoring the case) i.e. one!=two"); }
以下是一个完整示例。
示例
public class Demo { public static void main(String[] args) { String one = "rocky"; String two = "Rocky"; if(one.equalsIgnoreCase(two)) { System.out.println("String one is equal to two (ignoring the case) i.e. one==two"); }else{ System.out.println("String one is not equal to String two (ignoring the case) i.e. one!=two"); } } }
输出
String one is equal to two (ignoring the case) i.e. one==two
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP