wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes A little confuse with 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 "A little confuse with String" Watch "A little confuse with String" New topic
Author

A little confuse with String

Kay Liew
Ranch Hand

Joined: Dec 26, 2003
Posts: 112
KB books stated in page 357.

x.replace('a','A');
System.out.println("x = " + x); //the output is still: x = Java

I got trouble in the //comment. I think the original 'Java" will turns into 'JAvA".

Isn't that so ?

Thanks,
k


Unity can only be manifested by the Binary. Unity itself and the idea of Unity are already two.
Chris Allen
Ranch Hand

Joined: Feb 01, 2003
Posts: 127
Originally posted by Kay Liew:
KB books stated in page 357.

x.replace('a','A');
System.out.println("x = " + x); //the output is still: x = Java

I got trouble in the //comment. I think the original 'Java" will turns into 'JAvA".

Isn't that so ?

Thanks,
k


Look at what the x.replace('a','A') statement is really doing. Is it assigning the value it gets from the replace function to the string x or is it just performing the action and throwing the value away?
Kay Liew
Ranch Hand

Joined: Dec 26, 2003
Posts: 112
ok ok .. i looked too far

I was thinking of x.replace('a','A'); as x=x.replace('a','A'); .

k
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: A little confuse with String