What are the Methods used in StringBuffer in Java?
Java String Handling
Methods used in StringBuffer in java
length() and capacity():
=>The length() method is used to find the current length of a StringBuffer.
=>To find the total allocated capacity can be found though capacity() method.
Syntax:
int length()
int capacity()
ensureCapacity()
If we want to pre-allocate room for characters after a StringBuffer has been created.
Class sb1
{
public static void main(String args[])
{
StringBuffer sb=new StringBuffer(“HEERA”);
Sb.ensureCapacity(50);
Sop(“buffer= “+sb);
Sop(“length= “+sb.length());
Sop(“capacity= “+sb.capacity());
}
}