File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "String" Watch "String" New topic


John Mathew

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

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
I agree. Here's the link:
subject: String
It's not a secret anymore!