In this article, we will see how to use StringBuilder capacity method in Java.
The StringBuilder in Java provides a modifiable sequence of char acters. The String Class in Java creates and immutable sequence of char acters, the StringBuilder class provides an alternate to String Class, as it creates a mutable sequence of char acters.
The Java StringBuilder class is same to StringBuffer class, except it is non-synchronized.
Capacity method allows us to return how much char acter in our string .
Lets look to our code.
StringBuilder x = new StringBuilder("andromeda");
x.capacity();
Lets see it in an example.
In above example, we created a StringBuilder object. We used its capacity method to return size of our string .