This week's giveaway is in the EJB and other Java EE Technologies forum. We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan 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...