java中null和""的比较
直接上代码和截图
public static void main(String[] args) {
String s = null;
System.out.println(s != null);//false
System.out.println(s != "");//true
System.out.println("".equals(s));//false
System.out.println(!"".equals(s));//true
System.out.println(s != null || s != "");//true
System.out.println("****************");
String s2 = "";
System.out.println(s2 != null);//true
//
System.out.println(s2 == "");//true
//
System.out.println(s2 != "");//false
System.out.println("".equals(s2));//true
System.out.println(s2.equals(""));//true
System.out.println(!"".equals(s2));//false
System.out.println(s2 != null || s2 != "");//true
String s3 = "江西省赣州市于都县";
//
System.out.println(s2 == s3);//false
//
System.out.println(s2 != s3);//true
}
运行结果如下: