There is no way the code can work. hello and java without quotes are treated as variables. And since they are not declared before Compiler flags an error. Use of intern on a string object makes puts that it in the common pool of strings. that is String s1 = new String("a"); String s2 = new String("a"); In this case two objects created above are different, but if you use intern() above, then two objects share the same space and hence are same. Regards Gunjan
Is there more to the program that you forgot to mention? Did you perhaps define hello and java somewhere?
"I'm not back." - Bill Harding, Twister
Joined: Oct 29, 2002
Sorry , they are variables which I had declared. I am sorry for this!!
Joined: Jan 30, 2000
And did you perhaps give the variables values? Like <code><pre> String hello = "hello"; String java = "java";</pre></code> If so, then there's really no difference between <code><pre> System.out.println(hello + java);</pre></code> and <code><pre> System.out.println("hello" + "java");</pre></code> Should there be? It would be easier to answer your questions if you provided more information about what you're talking about, and why it confuses you. As for intern(), it's defined in String.intern().