day08-常用类-String-的比较的方法_equals_equalsIgnoreCase
This commit is contained in:
26
day08/src/com/inmind/string01/Demo03.java
Normal file
26
day08/src/com/inmind/string01/Demo03.java
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
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 s1 = "hello";
|
||||||
|
String s2 = new String("hello");
|
||||||
|
System.out.println(s1 == s2);//比较地址 false
|
||||||
|
System.out.println(s1);
|
||||||
|
System.out.println(s2);
|
||||||
|
System.out.println(s1.equals(s2));//比较内容 true
|
||||||
|
System.out.println("-----------------------");
|
||||||
|
String s3 = "HeLlo";
|
||||||
|
System.out.println(s1.equalsIgnoreCase(s2));//true
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user