Javatpoint Logo
Javatpoint Logo

Java StringBuilder append() method

The append() method of Java StringBuilder class is used to append the string value to the current sequence. There are various overloaded append() methods available in StringBuilder class. These methods are differentiated on the basis of their parameters.

Syntax:

Let's see the different syntax of StringBuilder append() method:

Parameter:

DataType Parameter Description
boolean b A boolean value which is to be appended.
char c A char value which is to be appended.
char str These are the characters which are to be appended.
int offset The index of the first char to append.
int len The number of characters to append.
CharSequence cs The character sequence that is to append.
int start This is the starting index of subsequence which is to be appended.
int end This is the end index of the subsequence which is to be appended.
double d A double value which is to be appended.
float f A float value which is to be appended.
int i An int value which is to be appended.
long lng A long value which is to be appended.
Object Obj An Object value which is to be appended.
String str A string value which is to be appended.
StringBuffer sb A StringBuffer which is appended.
int codePoint An int value of Unicode code point.

Returns:

Method Returns
append(boolean b) It returns a reference to this object.
append(char c) It returns a reference to this object.
append(char[] str) It returns a reference to this object.
append(char[] str, int offset, int len) It returns a reference to this object.
append(CharSequence cs) It returns a reference to this Appendable.
append(CharSequence cs, int start, int end) It returns a reference to this object.
append(double d) It returns a reference to this object.
append(float f) It returns a reference to this object.
append(int i) It returns a reference to this object.
append(long lng) It returns a reference to this object.
append(Object obj) It returns a reference to this object.
append(String str) It returns a reference to this object.
append(StringBuffer sb) It returns a reference to this object.
appendCodePoint(int codePoint) It returns a reference to this object.

Exceptions:

Method Exception
append(boolean b) NA
append(char c) NA
append(char[] str) NA
append(char[] str, int offset, int len) IndexOutOfBoundsException
append(CharSequence s) NA
append(CharSequence s, int start, int end) IndexOutOfBoundsException
append(double d) NA
append(float f) NA
append(int i) NA
append(long lng) NA
append(Object obj) NA
append(String str) NA
append(StringBuffer sb) NA
appendCodePoint(int codePoint) NA

Compatibility Version:

Java 1.5 and above

Example of Java StringBuilder append(boolean b) method

Test it Now

Output:

builderObject :value1 
after append = value1 true
new builderObject :value2 
after append = value2 false

Example of Java StringBuilder append(char c) method

Test it Now

Output:

builderObject :value1 
after append = value1 A
new builderObject :value2 
after append = value2 #

Example of Java StringBuilder append(char[] str) method

Test it Now

Output:

builderObject :string 
after append = string abc

Example of Java StringBuilder append(char[] str, int offset, int len) method

Test it Now

Output:

builderObject :string builder 
after append = string builder bcdef

Example of Java StringBuilder append(CharSequence cs) method

Test it Now

Output:

builderObject :string builder 
after append = string builder char sequence

Example of Java StringBuilder append(CharSequence cs, int start, int end) method

Test it Now

Output:

builderObject :string builder 
after append = string builder sequ

Example of Java StringBuilder append(double d) method

Test it Now

Output:

builder :string builder 
after append = string builder 12.65432101234568

Example of Java StringBuilder append(float f) method

Test it Now

Output:

builder :string builder 
after append = string builder 10.65

Example of Java StringBuilder append(int i) method

Test it Now

Output:

builder :append int 
after append = append int 100

Example of Java StringBuilder append(long lng) method

Test it Now

Output:

builder :append long 
after append = append long 9223372036854775807

Example of Java StringBuilder append(Object obj) method

Test it Now

Output:

builder :append object 
after append = append object objectValue

Example of Java StringBuilder append(String str) method

Test it Now

Output:

builder :append string 
after append = append string my string

Example of Java StringBuilder append(StringBuffer sb) method

Test it Now

Output:

builder :append stringBuffer 
after append = append stringBuffer bufferValue

Example of Java StringBuilder appendCodePoint(int codePoint) method

Test it Now

Output:

after append :
append codePoint1 @
append codePoint2 A






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA