• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String

 
John Mathew
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ...
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a cool trick...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic