Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A little confuse with String

 
Kay Liew
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Chris Allen
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok ok .. i looked too far

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

k
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic