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.
String functions do not actually change the String that invokes them. In your second example, what actually happened was that s.concat(s2) created a new String with value equivalent to "HelloJava" and returned it, but since no String reference received this return value, the change was not apparent. Note that the String s is still equivalent to "Hello". Try this: String newString = s.concat(s2); System.out.println("String s is " + s); System.out.println("String newString is " + newString);
Joined: Sep 10, 2002
I know the s.concat("java"); gives no change to s. but does String s="Hello" + "java"; give us the same as String s="Hellojava" ?
Joined: Mar 22, 2002
Yes, of course. Besides, you can see it for yourself by compiling it...