This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
System.out.println will print the returning value of the method. in this case s.toLowerCase() is returning a new String and it is being printed in the console....
plz correct if i am wrong
regards krishna bulusu
Joined: Mar 30, 2006
hi wise !
where the returned object by the method s.toLowerCase() in code A: goes
as in both cases references is not being cjanged
Joined: Feb 02, 2006
The created String Object will be lost because not variable to reference it. This is portion of code in my previous link. It show the process step by step.
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