java 字符串为空问题
String testStr = null;
System.out.println(testStr); if (testStr == null) {
System.out.println("testStr == null"); // 能正常打印 } if (testStr.equals("null")) {
System.out.println("testStr.equals null "); //Exception in thread "main" java.lang.NullPointerException }
String testStr="";
System.out.println("aaaa"+testStr); //能打印 if (testStr == null) {
System.out.println("testStr == null"); //不能打印 } if (testStr.equals("null")) {
System.out.println("testStr.equals null "); ////不能打印 } System.out.println("length:"+testStr.length()); // 打印length:0