StringReplaceExample -- comparing the effects of
String methods versus StringBuffer methods.
To see this example in action:
- Compile the Java source file, StringReplaceExample.java:
javac StringReplaceExample.java
- Run the class:
java StringReplaceExample
Output:
oldString before: java.lang.Thread
newString before: null
oldString after: java.lang.Thread
newString after: java/lang/Thread
sb1 before: sb1
sb2 before: sb2.
sb1 after: sb1 has been changed by append.
sb2 after: An insert has changed sb2.
The source.