Google News
logo
Java String Buffer
StringBuffer
1) String Buffer is a class present in the java.lang package.
2) StringBuffer is a final class so it can't be inharited.
3) StringBuffer is a mutable class so it is possible to change the content in the same location.
4) StringBuffer .equals() method is used for reference comparision. 

Constructors :
1) StringBuffer sb=new StringBuffer();
2) StringBuffer sb1=new StringBuffer(int capacity);
3) StringBuffer sb2=new StringBuffer(String str);
String Buffer program
class sup 
{ 
public static void main(String[] args) 
{ 
StringBuffer sb=new StringBuffer(); 
System.out.println(sb.capacity());//default capacity 16 
StringBuffer sb1=new StringBuffer(5); 
System.out.println(sb1.capacity());//your provided capacity 
StringBuffer sb2=new StringBuffer("freetimelearn"); 
System.out.println(sb2.capacity());//initial capacity+provided string length 24 
System.out.println(sb2.length()); //8 
} 
}
Output :
16 ,5 ,29 ,13
StinrgBuffer is mutable:-
Once we are creating a StringBuffer Object it is possible to the modification on existing object is called mutability nature.
String Buffer program
class sup 
{ 
public static void main(String[] args) 
{ 
StringBuffer s1=new StringBuffer("freetimelearn"); 
s1.append("hi");//mutability 
System.out.println(s1); 
} 
};
Output :
freetimelearnyhi