当我们写字符串的非空判断时会有两种写法
String b=null;
if("".equals(b)){
System.out.println(true);
}else{
System.out.println(false);
}当执行此代码时不会出错
if(b.equals("")){
System.out.println(true);
}else{
System.out.println(false);
}执行此代码可能会报错 java.lang.NullPointerException
if(b==null){
System.out.println(true);
}else{
System.out.println(false);
}
if(null==b){
System.out.println(true);
}else{
System.out.println(false);
}
这两种代码执行时结果是没有区别的