A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© PDH 中级黑马   /  2015-9-9 14:11  /  461 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

public class StringNullTest {

        /**
         * @param args
         */
        public static void main(String[] args) {
                // TODO Auto-generated method stub
                String str1="",str2=null;
                /*str1长度为0表示字符串""分配了内存空间,但值为空
                 * str2的值为null,没有分配内存空间,也不存在长度为多少,加str2.length()会发生编译错误
                 * null是用来判断引用类型是否分配了存储空间   
         * ""是针对字符串的;
                 * */
                System.out.println("空值为:"+str1+",长度为:"+str1.length()+"。");
                System.out.println("null字符串的值为:"+str2);
        }

}

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马