StringBuffer sb = new StringBuffer("Hello"); sb.append(" World!"); // appends " World!" to the existing string "Hello" System.out.println(sb.toString()); // "Hello World!"
StringBuffer sb = new StringBuffer("Numbers: "); sb.append(1).append(", ").append(2).append(", ").append(3); System.out.println(sb.toString()); // "Numbers: 1, 2, 3"
char[] arr = {'a', 'b', 'c'}; StringBuffer sb = new StringBuffer("Letters: "); sb.append(arr); System.out.println(sb.toString()); // "Letters: abc"The StringBuffer class is part of the Java Standard Library, specifically the java.lang package.