StringBuffer sb = new StringBuffer("Hello"); sb.append(" World"); System.out.println(sb.toString());
Hello World
StringBuffer sb = new StringBuffer(); sb.append("Java").append(" is").append(" cool"); System.out.println(sb);
Java is coolExplanation: In this code, we created a new StringBuffer object with no initial string value. We then used chained append() methods to add the strings "Java", "is", and "cool" to the object. Finally, we printed the resulting string to the console. Both of these examples use the java.lang package library.