asked 3.3k views
0 votes
Which of the following statements is true?

a. The capacity of a StringBuilder is equal to its length.
b. The capacity of a StringBuilder cannot exceed its length.
c. The length of a StringBuilder cannot exceed its capacity.
d. Both a and b are true.

asked
User EugeneZ
by
8.3k points

1 Answer

5 votes

Final answer:

The length of a StringBuilder cannot exceed its capacity.

Step-by-step explanation:

The correct statement is c. The length of a StringBuilder cannot exceed its capacity.

When a StringBuilder is created, it has an initial capacity, which is the number of characters it can hold without needing to allocate more memory. The capacity can increase as more characters are added to the StringBuilder, but the length of the StringBuilder cannot exceed its capacity.

For example, if a StringBuilder has a capacity of 10, it can hold up to 10 characters. If more than 10 characters are added, the StringBuilder will automatically increase its capacity to accommodate the extra characters.

answered
User HoosierDaddy
by
9.0k points
Welcome to Qamnty — a place to ask, share, and grow together. Join our community and get real answers from real people.