StringReplaceExample -- comparing the effects of String methods versus StringBuffer methods.
To see this example in action:
  1. Compile the Java source file, StringReplaceExample.java:
    	javac StringReplaceExample.java
    
  2. 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.