The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
October 2001



This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.


string thingeys

Posted by alex on October 31, 2001 at 11:36 PM

dear hiran.

hope this will answer ur ques. :)

case 1 : String s = new String();
u're creating a string which is empty but not null.

case 2 : String s = "";
it's the same as case 1. The string is empty but it's not null.

case 3 : String s = null;
in this case the string is initialized as null.

so for u, since u wanna check whether the returned string is null or not,
u better initialized it as the third case "String s = null". if u initialize the string using the first two ways, the checking part would be pointless.

or, u can use the first two ways. but check for the 'length'

this kinda initialization thingeys is analoous to set theory.
where an empty set is not the same as a null set.


Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us