File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes what is the difference between Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "what is the difference between "" and " "?" Watch "what is the difference between "" and " "?" New topic

what is the difference between "" and " "?

Guoqiao Sun
Ranch Hand

Joined: Jul 18, 2001
Posts: 317
Hi, what is the difference between "" and " "?

Guoqiao Sun<br />SCJP2 SCWCD2<br />Creator of <a href="" target="_blank" rel="nofollow"></a>, Java resource, mock exam, forum
Ranch Hand

Joined: Jul 17, 2001
Posts: 60
i guess, "" is equivalent to null whereas " " represents a white-space character.
correct me if i am wrong.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
No. "" does not equal null. "" represents an empty String but not a null.
Try comparing these two Strings:
s1 = "";
s2 = null;
The first test will answer false. The second test will throw a null pointer exception.

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Desai Sandeep
Ranch Hand

Joined: Apr 02, 2001
Posts: 1157
"" is an empty String, whereas " " is a non-empty blankspace character String
-- Sandeep
I agree. Here's the link:
subject: what is the difference between "" and " "?
It's not a secret anymore!