JAVA中isEmpty和null以及""的区别

来源:互联网 发布:上海达内java教育地址 编辑:程序博客网 时间:2024/05/17 23:31
/**  *   */  package JavaTest;    public class TestNull {        /**      * @param args      */      public static void main(String[] args) {          String a = new String();          String b = "";          String c = null;          if(a.isEmpty())          {           System.out.println("String a = new String");          }          if(b.isEmpty())          {           System.out.println("String b = \"\"");          }          if(c==null)          {           System.out.println("String c =null");          }          if(null == a) {              System.out.println("String a =null");          }          if(a=="")          {           System.out.println("a = ''");          }      }    } 


以上输出:


String a = new String  String b = ""  String c =null  

此时a是分配了内存空间,但值为空,是绝对的空,是一种有值(值存在为空而已)  此时b是分配了内存空间,值为空字符串,是相对的空,是一种有值(值存在为空字串)  此时c是未分配内存空间,无值,是一种无值(值不存在) 


0 0
原创粉丝点击