java.lang.StringBuffer append(char[] str)

Description :

This java tutorial shows how to use the append(char[] str) method of StringBuffer class under java.lang package. The append method of StringBuffer class is overloaded which takes different data type as input however on this case the input is character array data type thus the string equivalent of the character array method input is appended on the base string.

Method Syntax :

public StringBuffer append(char[] str)

Parameter Input :

DataType Parameter Description
char[] str The character array that would be appended to the base string.

Method Returns :

The append(char[] str) method simply returns the reference object which is the combined String representation of the base string and the character array method argument.

Compatibility Version :

Requires Java 1.0 and up

Discussion :

The append method is overloaded thus this method can generally takes different data types however on this case it is char array. Technically speaking the char[] str method argument is converted using the static method String,valueOf(char[] str).

Java Code Example :

This java example source code demonstrates the use of append(char[] str) method of StringBuffer class. Basically this code just utilize the append(char[] str) in combining the character array as given as one of the variable. This source code is a good example in learning on how to initialize StringBuffer object, modify the contents of the StringBuffer object and printing of the current String on the buffer.


import static java.lang.System.*;

import java.util.Scanner;

 * This example source code demonstrates the use of append(char[] str)
 * of StringBuffer class

public class StringBufferAppendCharArray {

	public static void main(String[] args) throws IOException {

		String name = "Andrew";
		char[] lastName = "Carnegie".toCharArray();

		// initialize the StringBuffer object
		StringBuffer sb = new StringBuffer(name + "|");
		System.out.println("Contents of Buffer:" + sb.toString());



Sample Output :

Running the append(char str) method example source code of StringBuffer class will give you the following output

Contents of Buffer:Andrew|Carnegie

Exception Scenario :


Similar Method :

  • N/A

Suggested Reading List :

References :