Multiple choice

Which of the following methods is used to pre-allocate a space for a certain number of characters, after a StringBuffer has been constructed?

  1. setLength()

  2. length()

  3. capacity()

  4. startWith()

  5. ensureCapacity()

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

This method is used to pre-allocate a space for a certain number of characters, after a StringBuffer has been constructed. This method determines whether a given string begins with a specified string or not.