217k views
0 votes
Given the following declaration:

StringBuilder buf = new StringBuilder();
What is the capacity of buf?

a. 0
b. 10
c. 16
d. 20"

User Neophyte
by
8.0k points

1 Answer

5 votes

Final answer:

The default capacity of a StringBuilder when instantiated with the default constructor is 16. This capacity refers to the internal character storage size and it can expand if necessary.

Step-by-step explanation:

When a StringBuilder is created using its default constructor, as in the declaration StringBuilder buf = new StringBuilder();, the initial capacity of the StringBuilder is 16. Capacity refers to the amount of space that is currently allocated for storing the sequence of characters. The answer to the question is: c. 16. It's important to note that the capacity can automatically increase if the string grows beyond this initial capacity.

User Eriaac
by
8.1k points