day08--常用类-String-的比较的方法_equals_equalsIgnoreCase

This commit is contained in:
xx
2026-09-22 11:25:38 +08:00
parent efc98db11b
commit 851cb0c2aa
+22
View File
@@ -0,0 +1,22 @@
package com.inmind.string01;
/*
常用类-String-的比较的方法_equals_equalsIgnoreCase
public boolean equals (Object anObject) :将此字符串与指定对象进行比较。
public boolean equalsIgnoreCase (String anotherString) :将此字符串与指定对象进行比较,忽略大小写。
*/
public class Demo03 {
public static void main(String[] args) {
String str1 = "abc";
String str2 = new String("abc");
System.out.println(str1);
System.out.println(str2);
System.out.println(str1 == str2);//str1和str2的地址不同,只是他们指向最终的内容是相同,所以此处是false
System.out.println(str1.equals(str2));//这才是比较内容,这才是开发时所需的操作
String str3 = "AbC";
System.out.println(str1.equals(str3));
System.out.println(str1.equalsIgnoreCase(str3));
}
}