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

 

相关文章:

  • 2022-02-21
  • 2022-02-04
  • 2022-12-23
  • 2021-12-04
  • 2022-12-23
  • 2021-07-24
  • 2022-12-23
猜你喜欢
  • 2021-05-17
  • 2021-11-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-04
相关资源
相似解决方案