• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

A little confuse with String

 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
It's weird that we cook bacon and bake cookies. Eat this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic