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.
dear ranchers, String s = "please help"; //1 s.concat(" me!"); //2 System.out.print(s); //3 Why it prints "please help" without " me!" ? I kind of know that if I change line //2 to be like s = s.concat(" me!") then it will create brand new String object & output will be "please help me!". So what is the reason to use conctat() method without creating brand new String object like i have on line //2 ??? Any help would we great ! thx
Ivan, Because strings are immutable, a new string is created everytime we try to modify it.So in your case s.concat("me") creates a new string object and s still remains the same. Hope this helps Kareem