// Test some of the StringBuffer methods. public class TestStringBuffer { public static void main(String[ ] argv) { // Test constructors. StringBuffer a = new StringBuffer( ); StringBuffer b = new StringBuffer(20); StringBuffer c = new StringBuffer("mississippi"); // Print StringBuffer objects, their lengths and capacities; System.out.println("*" + a + "* " + a.length( ) + " " + a.capacity( )); System.out.println("*" + b + "* " + b.length( ) + " " + b.capacity( )); System.out.println("*" + c + "* " + c.length( ) + " " + c.capacity( )); // Test overloaded append methods. c.append(3.14); c.append("$$$$$"); System.out.println(c); // Test overloaded delete methods. c.delete(2, 4); System.out.println(c); c.deleteCharAt(10); System.out.println(c); // Test overloaded insert methods. c.insert(0, 2.78); c.insert(5, "%%%"); System.out.println(c); // Test replace method. c.replace(4, 6, "xyz"); System.out.println(c); // Test reverse method. c.reverse( ); System.out.println(c); // Test setCharAt method. c.setCharAt(0, '~'); System.out.println(c); // Test setLength method. c.setLength(5); System.out.println("*" + c + "* " + c.length( )); c.setLength(7); System.out.println("*" + c + "* " + c.length( )); } } // Output: ** 0 16 ** 0 20 *mississippi* 11 27 mississippi3.14$$$$$ miissippi3.14$$$$$ miissippi314$$$$$ 2.78m%%%iissippi314$$$$$ 2.78xyz%%iissippi314$$$$$ $$$$$413ippissii%%zyx87.2 ~$$$$413ippissii%%zyx87.2 *~$$$$* 5 *~$$$$ * 7