Methods of the StringBuilder object in Java

In addition to the charAt(), indexOf(), substring(), length() methods that work in the String object, StringBuilder has other main methods that we’ll cover in the following:

The append() method adds a value at the end of the current string of the StringBuilder object. We can add a variety of data types using overloading methods of this method.
For example:

Learn about StringBuilder object in Java

The insert() method inserts data at any location in the StringBuilder object.
For example:

Learn about StringBuilder object in Java

The delete() method with two start and end arguments is used to delete a string with the start and end indexes.
For example:

Learn about StringBuilder object in Java

Note that this method will not delete the character at the end index!

The deleteCharAt() method deletes a character at any location in the string of the StringBuilder object.
For example:

Learn about StringBuilder object in Java

The reverse() method reverses the characters in the string of the StringBuilder object.
For example:

Learn about StringBuilder object in Java

The replace() method replaces any string from the start index to the end index in the string of the StringBuilder object.
For example:

Learn about StringBuilder object in Java

As the delete() method, the character at the end will not be counted in the character to replace!

The subsequence() method takes a string from the start index to the end index in the string of the StringBuilder object.
Note that using the subsequence() method will not change our StringBuilder object, and the new string will not have the character at the end.

For example:

Learn about StringBuilder object in Java

Add Comment