StringBuilder capacity() in Java with Examples
The capacity() method of StringBuilder Class is used to return the current capacity of StringBUilder object. The capacity is the amount of storage available to insert new characters.
public int capacity()
Return Value: This method returns the current capacity of StringBuilder Class.
Below programs demonstrate the capacity() method of StringBuilder Class:
Default Capacity of StringBuilder = 16 StringBuilder = Geek Current Capacity of StringBuilder = 16
StringBuilder = WelcomeGeeks Capacity of StringBuilder = 28
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.