This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Strings ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Strings ?" Watch "Strings ?" New topic
Author

Strings ?

rahul kumar
Ranch Hand

Joined: Feb 24, 2001
Posts: 75
The statement ...
String s = "Hello" + "Java";
yields the same value for s as ...
String s = "Hello";
String s2= "Java";
s.concat( s2 );
a) True
b) False
what is the answere with explaination.
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
this is false since the value of s after the concatenation will still be "Hello" and not "HelloJava"
remember that STring objects are immutable anf thus can't be changed with mutator method like concat... A new referecne to a new String object is returned...
HIH
------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
sai murali
Greenhorn

Joined: Oct 03, 2001
Posts: 13
s.concat( s2 );
It will not change the original content of s, will result a new String variable.
So s value will be still "Hello", but the previous
s value is "HelloJava".
Answer is false(b).


saimurali
 
Consider Paul's rocket mass heater.
 
subject: Strings ?
 
Similar Threads
concat
MindQ's question no. 11
String Concat
String Question
String