Can some body please tell me difference between String s = "" and String s1 = null; I think a object is made in first case and not in second case, but then what is the value contained in first case, also what is difference values in s = "" and s = " "(i.e. with a space)
Hi, Akhil. You are correct, String s = ""; creates an Object, whereas String s = null; does not. As for the contents of s when it contains an empty string, according to a comment in the source code of java.lang.String, "There is an empty string at index 0 in an empty string." Paradoxical, but it explains why s.endsWith( "" ) and s.startsWith( "" ) return true. Also, String s = ""; is completely different from String s = " ";. An empty string is not the same as a String containing a space. Hope this helps, Akhil. Art
Create symphonies in seed and soil. For this tiny ad:
a bit of art, as a gift, that will fit in a stocking