 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Get the capacity of the StringBuffer Object in Java
The capacity() method is a method of the StringBuffer class . It returns the quantity of storage present for recently inserted characters, after which an allocation occurs.
Declaration-The java.lang.StringBuffer.capacity() method is declared as follows−
public int capacity()
Let us see an example program showing how to get the capacity of the StringBuffer Object.
Example
import java.lang.*; public class Example {    public static void main(String[] args) {       StringBuffer b = new StringBuffer(“Hello”);       // returns the current capacity of the String buffer which is 16 + 5 = 21       System.out.println("Capacity for the StringBuffer Object = " + b.capacity());    } }  Output
Capacity for the StringBuffer Object = 21
Advertisements
 