正确的写法是 if(str1==null||str1.equals("")){ //所以在判断字符串是否为空时,先判断是不是对象,如果是,再判断是不是空字符串 }
if(str != null && str.length() != 0) { }
1. str!=null;
2. "".equals(str);
3. str.length()!=0;
5 if(s == null || s.equals(""));
5 if(s == null || s.length() <= 0);
5 if(s == null || s.isEmpty()); jdk6.0之后
function 1 use time: 141ms
function 2 use time: 46ms
function 3 use time: 47ms
评论区