java.lang.String.isEmpty()的用法
首先,来看isEmpty()的定义:
Declaration
Following is the declaration for java.lang.String.isEmpty() method
public boolean isEmpty()
Parameters
-
NA
Return Value
This method returns true if length() is 0, else false.
Exception
-
NA
1.在实际情况中,常有条件:
if(!str.isEmpty()){
//如果字符串长度>0,则...
}
但是,在无法判断字符串是否为null的时候,应当完善上述条件:
if(str!=null && !str.isEmpty()){
//如果字符串长度>0,则...
}
2.对于"".equals(str),则equals will
check its argument and return false if
it"s null。用法和isEmpty()是一样的。
声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
- 上一篇:没有了
- 下一篇:没有了
