如何判断字符串、list是否为空

对字符串是否为空的判断:

if(s == null || "".equals(s)){}//直观但效率低
if(s == null || s.lenth() <=0){}//效率高,推荐使用
if(s == null || s.isEmpty() ){}
if(s == null || s == ""){}

 注:

length()是取得字符串的长度;

""表示一个长度为0的字符串,是一个对象,有分配空间;

null不表示任何对象,没有分配空,所以易出现空指针异常

对list是否为空的判断:

if(list != null && !list.isEmpty()){}
原文地址:https://www.cnblogs.com/jodiegreat/p/6674224.html