Results 1 to 5 of 5
  1. #1
    Jagdeesh123 is offline Member
    Join Date
    Nov 2010
    Posts
    9
    Rep Power
    0

    Post null v/s empty String(" ")

    if(myString.equals("")){

    }

    if(myString.equals(null)){

    }


    wat is the difference between " "(empty string) and null string

  2. #2
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    10

    Default

    "" 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

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,313
    Blog Entries
    1
    Rep Power
    31

    Default

    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.

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,716
    Rep Power
    18

    Default

    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.

  5. #5
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    10

    Default

    Quote Originally Posted by Fubarable View Post
    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.
    Thanks. Now I can never eat eggs non-existentially again.

Similar Threads

  1. String output showing "null"
    By hayden06f4i in forum New To Java
    Replies: 6
    Last Post: 11-05-2010, 10:21 AM
  2. string comparison with "=" and ".equal"
    By guavajuice in forum New To Java
    Replies: 9
    Last Post: 04-22-2010, 09:01 PM
  3. Replies: 2
    Last Post: 03-19-2010, 05:30 PM
  4. Replies: 0
    Last Post: 04-02-2009, 07:02 PM
  5. Replies: 1
    Last Post: 10-20-2008, 07:35 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •