• 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

String inNutShell

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi jerry...
here is how Strings works:

whenever you apply any method on string objects, compiler automatically generates a new copy of orgional string objects, performs operation on new one and then returns the modiifed string objects. old one is not touched. so its up to you if you want to assign the reutrned object a reference or not.

Example:

String s = "XYZ"; //1. a object created

s.concat("ABC"); //now a fresh copy of XYZ created and "ABC" to it and the
//reference to XYZABC returned, but it get lost
//as you are not assiging reference to it.
System.out.println(s); // its "XYZ"

now lets see if you write:

System.out.println(s.concat("ABC")); //it will print XYZABC but the s=XYZ

if you write:
s = s.concat("ABC"); //then s=XYZABC
 
I knew that guy would be trouble! Thanks tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic