A Developer Gateway To IT World...

Techie Uncle Software Testing Core Java Java Spring C Programming Operating System HTML 5 Java 8 ES6 Project

Methods used in StringBuffer

Methods used in StringBuffer in java

What are the Methods used in StringBuffer in Java?

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()

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”); 
  Sop(“buffer= “+sb); 
  Sop(“length= “+sb.length()); 
  Sop(“capacity= “+sb.capacity());