首先,来看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()是一样的。