StringBuffer class Example Program

Java StringBuffer class

Java StringBuffer class is used to create mutable (modifiable) string. The StringBuffer class in java is same as String class except it is mutable i.e. it can be changed.

Example Program :


class StringBufferDemo
{
public static void main(String args[])
{
StringBuffer str=new StringBuffer("WELCOME");

System.out.println(str);
System.out.println(str.append(" to JAVA"));
System.out.println(str.insert(4,"HOW"));
System.out.println(str.delete(4,7));
System.out.println(str.reverse());
System.out.println(str.indexOf("WELCOME"));
System.out.println(str.charAt(6));
System.out.println(str.substring(8));
 }
}

Comments