string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jyohere
    New Member
    • Apr 2007
    • 73

    #1

    string

    what is the difference between

    String str=null;
    String str=" "; and
    String str="";
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by jyohere
    what is the difference between

    String str=null;
    String str=" "; and
    String str="";
    The second and third initialization set str to an actual string value. The string in
    the second initializer contains a single space character. The string in the third
    initializer is emty.

    The first initializer set the str reference to the value null, i.e. str doesn't refer to a
    string value.

    kind regards,

    Jos

    Comment

    • gaya3
      New Member
      • Aug 2007
      • 184

      #3
      Hi jyo,

      Difference between String x=null;String x="";String x=" " is as follows,
      a) In third initialization, String with "blank space" is assigned to String x;
      b) In First initialization, null is a condition where the variable (a reference pointer) is completely empty. It is not pointing to any object at all.
      c) In second initialization, empty string is asigned to String x;
      A empty string is where there is a String object, but its contents have zero length, there is nothing in it.

      Comment

      Working...