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

 

posted @ 2016-03-31 09:39  testway  阅读(572)  评论(0编辑  收藏  举报