首页 > 其他 > 详细

Difference between null and empty String

时间:2014-09-18 06:27:43      阅读:214      评论:0      收藏:0      [点我收藏+]

String s1 = ""; means that the empty String is assigned to s1. In this case, s1.length() is the same as "".length(), witch will yield 0 as expected.

String s2 = null; means that (null) or "no value at all" is assigned to s2. To this one,s2.length() is the same as null.length(), witch will yield a NullPointerException as you can‘t call methods on null variables (pointers, sort of) on Java.

Also, a point, the statement

String s1;

Actually has the same effect as:

String s1 = null;

Whereas

String s1 = "";

Is, as said, a different thing.

Difference between null and empty String

原文:http://www.cnblogs.com/EdwardLiu/p/3978457.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!