java 字符串为空问题

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
原文地址:https://www.cnblogs.com/testway/p/5339959.html