1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
/* Java StringBuffer Example This example shows how java StringBuffer can be built and created using different constructors of Java StringBuffer class. */ public class JavaStringBufferExample { public static void main(String[] args) { /* Java StringBuffer is a mutable sequence of characters. Difference between Java String and StringBuffer is that StringBuffer can be modified while String can not. Java StringBuffer can buit using one of the following constructors */ /* 1. StringBuffer StringBuffer() Construct empty StringBuffer with initial capacity of 16 */ StringBuffer sbObj1 = new StringBuffer(); /* 2. StringBuffer StringBuffer(int length) Constructs empty StringBuffer with initial capacity of length */ StringBuffer sbObj2 = new StringBuffer(10); /* 3. StringBuffer StringBuffer(String str) constructs StringBuffer with the contents same as argument String */ StringBuffer sbObj3 = new StringBuffer("Hello World"); System.out.println(sbObj3); } } /* Output would be Hello World */ |
i found this site very informative thank you