216k views
2 votes
Which of the following is true?

1) You can add characters into a string buffer.
2) You can delete characters into a string buffer.
3) You can reverse the characters in a string buffer.
4) The capacity of a string buffer can be automatically adjusted.

User Sharad
by
7.5k points

1 Answer

5 votes

Final answer:

All the given statements about the Java StringBuffer class are true. It enables adding, deleting, and reversing characters, as well as automatically adjusting capacity during string manipulations.

Step-by-step explanation:

You are correct in that the StringBuffer class in Java provides several functionalities. To answer your question, here are the accurate statements among the ones you've listed:

  • You can add characters into a StringBuffer.
  • You can delete characters from a StringBuffer.
  • You can reverse the characters in a StringBuffer.
  • The capacity of a StringBuffer can be automatically adjusted.

Therefore, all the statements you mentioned are true for a StringBuffer. It's designed to be a mutable sequence of characters with the ability to be modified through various methods without needing to create a new object each time a change is made. This makes it more efficient for string operations that require frequent modifications.

User Pashupati Khanal
by
8.3k points