Java StringBuilder Methods Descriptions Examples
Java StringBuilder Methods Descriptions Examples
1. append(String str)
- Description: Appends the specified string to the end.
- Example:
sb.append("Hello");
5. reverse()
- Description: Reverses the characters in the sequence.
- Example:
sb.reverse();
6. capacity()
- Description: Returns the current capacity of the buffer.
- Example:
int cap = sb.capacity();
7. ensureCapacity(int minimumCapacity)
- Description: Ensures that the capacity is at least equal to the specified minimum.
- Example:
sb.ensureCapacity(50);
9. charAt(int index)
- Description: Returns the character at the specified index.
- Example:
char ch = sb.charAt(1);
10. length()
- Description: Returns the length (character count).
- Example:
int len = sb.length();