equalsIgnoreCase()方法与equals()的区别
程序员文章站
2022-07-14 12:03:26
...
-
equalsIgnoreCase()是从词意上直译就能大概知道他的意思了。equalsIgnoreCase()和equals()都是比较字符串的内容,但equalsIgnoreCase()忽略大小作比较。equals()比较时区分大小写
-
“= =” 和前两个都不一样,他比较的是地址,也就是说就是equalsIgnoreCase()和equals()都为true,“= =”也有可能是假
代码如下:
package test
object Test_equals {
def main(args: Array[String]): Unit = {
val a = "hello"
val b = "HELLO"
val c = "hello"
println("a:"+a+"\n"+"b:"+b+"\n"+"c:"+c)
println("a.equals(c) is "+ a.equals(c))
println("a.equals(b) is "+ a.equals(b))
println("a.equalsIngoreCase(b) is "+ a.equalsIgnoreCase(b))
}
}
输出结果:
a:hello
b:HELLO
c:hello
a.equals(c) is true
a.equals(b) is false
a.equalsIngoreCase(b) is true