freetimestudys@gmail.com          +91-7097633380
  Login Here                        

StringBuffer reverse( ):

 This reverses the character sequence in the StringBuffer.

StringBuffer reverse program

class Test
{
public static void main(String[] args)
{
StringBuffer sb=new StringBuffer("abc");
System.out.println(sb);
}
}

intput and output

output:cba

StringBuffer append

‘x’ may be boolean, byte, int, long, float, double, char, character array, String or another StringBuffer. It will be added to StringBuffer object

StringBuffer append program

class Test
{
public static void main(String[] args)
{
StringBuffer sb=new StringBuffer("rattaiah");
String str=" salary ";
int a=30000;
sb.append(str);
sb.append(a);
System.out.println(sb);
}
}

intput and output

output:rattaiah salary 30000

String Buffer Insert

By using above method we are able to insert the string any location of the existing string.

String Buffer Insert program

class Test
{
public static void main(String[] args)
{
StringBuffer sb=new StringBuffer("freetimestudy");
sb.insert(0,"hi ");
System.out.println(sb);
}
}

intput and output

output:hi freetimestudy

StringBuffer delete

This removes the characters from ith position till j-1th position in the StringBuffer.

String Buffer delete program

class test
{
public static void main(String[] args)
{
StringBuffer sb=new StringBuffer("freetimestudy");
sb.delete(1, 3);
System.out.println(sb);
}

intput and output

output:fetimestudy

StringBuffer replace

This replaces characters from i to j-1, by the string ’str’ in StringBuffer object.

StringBuffer replace

class sup
{
public static void main(String[] args)
{
StringBuffer sb=new StringBuffer("freetimestudy");
sb.replace(1,2,"hi");
System.out.println(sb);
}

intput and output

output:fhieetimestudy

String toString

This converts the StringBuffer object into a string object.

String toString program

class sup
{
public static void main(String[] args)
{
StringBuffer sb=new StringBuffer("freetimestudy");
String s=sb.toString();
System.out.println(s);
}

intput and output

output:freetimestudy

StringBuilder:-

Java.lang.StringBuilder:-
1) Introduced in jdk1.5 version.
2) StringBuilder is identical to StringBuffer except for one important difference.
3) Every method present in the StringBuilder is not Synchronized means that is not thread safe.
4) multiple threads are allow to operate on StringBuilder methods hence the performance of the application is increased.