Basic example using String Buffer Class in Java


Here is the simple program for printing basic example using string buffer in Java.

Source Code

import java.io.*;
import java.util.Scanner;
class str
{
  public static void main(String args[])
  {
   int i,n;
   // str="Tutor Joes";
   StringBuffer str =new StringBuffer("Tutor Joes");
   System.out.print("\nOriginal Message : "+str);
   n=str.length();
   System.out.print("\nLength : "+n+"\n");
   for(i=0;i<n;i++)
   {
     System.out.print("   "+str.charAt(i));
   }
   String a=new String(str.toString());
   int pos = a.indexOf(" ");
   System.out.print("\nLocation : "+pos);
   str.insert(pos," Computer");
   System.out.print("\nModify Message : "+str);
   str.setCharAt(6,'*');
   System.out.print("\nModify Message : "+str);
   str.append(" Very Good");
   System.out.print("\nModify Message : "+str);
  }
}
To download raw file Click Here

Output

Original Message : Tutor Joes
Length : 10
   T   u   t   o   r       J   o   e   s
Location : 5
Modify Message : Tutor Computer Joes
Modify Message : Tutor *omputer Joes
Modify Message : Tutor *omputer Joes Very Good


Learn All in Tamil © Designed & Developed By Tutor Joes