aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes String inNutShell Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "String inNutShell" Watch "String inNutShell" New topic
Author

String inNutShell

Amit Prakash Singh
Ranch Hand

Joined: May 11, 2006
Posts: 38
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


Amit Prakash Singh<br /> <br />SCJP 1.4 93% <br />SCWCD1.5 85%
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: String inNutShell
 
Similar Threads
Very Important String Questions
doubt in string question in Kathy Sierras SCJP book
String is immutable object but??
string objects
Why strange output of this String question