PDA

View Full Version : String


selvi
02-10-2009, 10:46 AM
what is the difference between null value and empty string?

jeyasree
02-10-2009, 11:01 AM
Very big!

Empty String is an OBJECT of type: String (new String()

)
It means there is an object associated to variable and you can call object methods:
String s = new String(); //object initialization (empty string)
System out println( s.length() );


NULL String means that there is no reference to any OBJECT.
String s;
System.out.println( s.length() ); //this will throw NullPointerException

servlet
02-10-2009, 02:17 PM
Follow Posting guidelines (http://www.codingforums.com/postguide.htm) for better response