File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes String Concat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "String Concat" Watch "String Concat" New topic
Author

String Concat

Santosh Jaiswal
Greenhorn

Joined: Oct 04, 2000
Posts: 26
The statement ...
String s = "Hello" + "Java";
yields the same value for s as ...
String s = "Hello";
String s2= "Java";
s.concat( s2 );
1. True 2.False
How the answer is False

Harpal Singh
Ranch Hand

Joined: Oct 10, 2000
Posts: 229
Originally posted by Santosh Jaiswal:
The statement ...
String s = "Hello" + "Java";
yields the same value for s as ...
String s = "Hello";
String s2= "Java";
s.concat( s2 );
1. True 2.False
How the answer is False


Santosh,
Answer will be false coz after this statement:
String s = "Hello" + "Java";
a String pool will be created which will hold "HelloJava",and variable s will point to that...and when you say
String s = "Hello";
String s2= "Java";
s.concat( s2 );
a new pool of String will be created ie HelloJava,but s is still pointing to the other pool of string...now if you say
s=s.concat( s2 );
then the answer will be true coz now your variable s is being assigned to a new string which contains "HelloJava"...
Hope it clears your doubt....
thanks,
Harpal...
Santosh Jaiswal
Greenhorn

Joined: Oct 04, 2000
Posts: 26
Oh! I got it, I was just skipping the assignment part.
Thanks Harpal.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: String Concat