if(myString.equals("")){
}
if(myString.equals(null)){
}
wat is the difference between " "(empty string) and null string
Printable View
if(myString.equals("")){
}
if(myString.equals(null)){
}
wat is the difference between " "(empty string) and null string
"" contains no characters, but is still a reference to an empty string. null contains no reference data, so basically it doesn't exist at all. Does that make sense or do you want a better explanation?
PS: Have a look at this: http://hanuska.blogspot.com/2006/08/empty-string.html
Think of an empty String like an empty egg crate, a String with characters, the same container with eggs, and a null reference -- no egg crate at all.
We speak loosely about a null string: but there is, literally, no such thing.
myString.equals("") is true when the value of the variable myString is a pointer to a string with no characters in it.
myString.equals(null) is true when the variable myString has a special value that refers to no string whatsoever.