Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "String" Watch "String" New topic
Author

String

John Mathew
Greenhorn

Joined: Apr 17, 2007
Posts: 13
The statement ...

String s = "Hello" + "Java";

yields the same value for s as ...

String s = "Hello";
String s2= "Java";
s.concat( s2 );
Vassili Vladimir
Ranch Hand

Joined: Mar 08, 2007
Posts: 1585
Pay very well attention to these statements Dear John,

In the first one, s will contain "Hello Java"

Where in the second one, when saying

This String literal will be lost!

s will contain "Hello" only!

For more about Strings and immutability, please refer to the great material enclosed in the K&B book., you will understand everything clearly ...

Best of luck ...


Vassili ...
SCJP 5.0, SCWCD 1.4, SCJA 1.0
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Here's a cool trick...


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: String