Files
javaSE-0113/day08/src/com/inmind/string01/Demo03.java

31 lines
1.1 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.inmind.string01;
/*
常用类_String的比较的方法_equals_equalsIgnoreCase
String的比较
==表示比较String对象的地址其实没有任何意义==一般用于基本数据类型的值是否相等比较
equals表示比较String对象地址所指向的内容
比较的方法:
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);//比较地址,错误操作
boolean result = str1.equals(str2);//比较内容,正确操作
System.out.println(result);//true
String str3 = "AbC";
System.out.println(str1.equals(str3));//false
System.out.println(str1.equalsIgnoreCase(str3));//true
}
}