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
Posted by Hiran on October 30, 2001 at 10:10 PM
Quick question. Are the following lines equivalent?
(1) String p = new String();
(2) String p = null;
(3) String p = "";
If they are not all equivalent, which ones are? Or are they all different? If so, what does each one print out? I'm asking cause at times I need to print a string that contains null (if a certain condition is not met, otherwise the string contains stuff). Thnx in advance!