标题基本上都说明了一切.我通常在一起测试这个string == null,所以我并不真正关心一个零安全测试.我应该使用哪个?
String s = /* whatever */;
...
if (s == null || "".equals(s))
{
// handle some edge case here
}
Run Code Online (Sandbox Code Playgroud)
要么
if (s == null || s.isEmpty())
{
// handle some edge case here
}
Run Code Online (Sandbox Code Playgroud)
在那个笔记 - isEmpty()甚至做除了return this.equals("");或以外的任何事情return this.length() == 0;?