capacity(): This method is available in java.lang.AbstractStringBuilder class of Java.
Syntax:
int java.lang.AbstractStringBuilder.capacity()
This method returns the current capacity. The capacity is the number of characters that can be stored (including already written characters), beyond which an allocation will occur.
Parameters: NA
Returns: the current capacity.
For Example:
StringBuilder str = new StringBuilder("Hello 123")
str.capacity() = > It returns 25.
Approach
Java
public class Capacity {public static void main(String[] args) {StringBuilder str = new StringBuilder("Hello 123");System.out.println(str.capacity());}}
Output:
25
No comments:
Post a Comment