java中的字符串判断

100 阅读1分钟

字符串相等判断

1.equals

通过此函数判断两个字符串是否相等

2.equalsIgnoreCase()

equalsIgnoreCase作用一般是用来比较字母的长度和字符是否相同,且不区分大小写(常用于进行验证码校验)

字符串判空(isEmpty 与 isBlank 区别)

1.isEmpty()

isEmpty(null)----true
isEmpty("") -----true
isEmpty(" ")-----flase
isEmpty("test")--flase

2.isBlank()

isBlank(null)----true
isBlank("")------true
isBlank(" ")-----true
isBlank("test")--flase
isBlank("\t \n \f \r")------true(//制表符、换行符、换页符和回车符)

isBlank相较于isEmpty级别更高,在isEmpty的基础上增加为空(字符串都为空格、制表符、tab 的情况)的判断