![]() |
VOOZH | about |
In Java, the append() method of StringBuilder class is used to add data to the end of an existing StringBuilder object. It supports appending different data types like strings, integers, characters, and booleans by making it easy for dynamic string manipulation.
Example 1: Here, we use the append() method to add a string to a StringBuilder object.
Java Programming
Now there are several versions of the append() method in StringBuilder and each version designed to append different types of data, such as strings, different data types, objects, or even subsequences.
public StringBuilder append(data)
Example 2: In this example, we use the append() method to add various data types to the StringBuilder object.
The value is 21, 7.01, or false
Example 3: StringBuilder append(char[] str, int offset, int len)
This version appends a subarray of characters to the StringBuilder, starting at the specified offset and with the specified length.
Syntax:
public StringBuilder append(char[] str, int offset, int len)
Parameter:
Return Type: StringBuilder: The method returns the same StringBuilder instance with the appended characters.
Programming in J
Example 4: StringBuilder append(CharSequence chseq, int start, int end)
This version appends a subsequence of characters from a CharSequence to the StringBuilder by using specified start and end indices.
Syntax:
public StringBuilder append(CharSequence chseq, int start, int end)
Parameter:
Return Type:
Welcome to rogrammin
Example 5: StringBuilder append(Object obj)
This version appends the string representation of an object to the StringBuilder.
Syntax:
public StringBuilder append(Object obj)
21
Example 6: This example demonstrates chaining multiple append() calls.
Java is a Programming Language.