Have you tried compiling this? I see at least 10 typos.
Remember,
Java is case sensitive, and parentheses and braces are quite different. The output is actually
javajavaC (and that 'C' was probably intended to be lowercase).
The idea illustrated here is that Strings are immutable. When you call myString.replace('a', 'b'), the original String is
not changed in any way. Instead, a
new String is created with the replaced chars.
In contrast, a StringBuffer is mutable. When you call myStringBuffer.append("Str"), the original StringBuffer's contents is appended with the argument String.
Therefore, the output will be the original String,
unchanged by the call to replace, concatenated with a String representation of the StringBuffer, which
has been changed to include the appended "c".
So the result is "java" and "javac." (Get it?
)
[ July 28, 2007: Message edited by: marc weber ]