On this document we will be showing a java example on how to use the append() method of BigInteger Class. The append() method is overloaded. It can accept multiple data type which is the following:

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

A quick background on Method Overloading

Method overloading is one of the feature of java where we can use the same method name but with different method signature.

Method Syntax

  • public StringBuilder append(Object obj)
  • public StringBuilder append(String str)
  • public StringBuilder append(StringBuffer sb)
  • public StringBuilder append(CharSequence s)
  • public StringBuilder append(CharSequence s, int start, int end)
  • public StringBuilder append(char[] str)
  • public StringBuilder append(char[] str, int offset, int len)
  • public StringBuilder append(boolean b)
  • public StringBuilder append(int i)
  • public StringBuilder append(long lng)
  • public StringBuilder append(float f)
  • public StringBuilder append(double d)

Method Returns

The append() method returns this StringBuilder with the method argument appended.


Requires Java 1.5 and up

Java StringBuilder append() Example

Below is a java code demonstrates the use of append() method of BigInteger class. The example presented might be simple however it shows the behavior of the append() method.


 * A java example source code to demonstrate
 * the use of append() method of StringBuilder class

public class StringBuilderAppendExample {

	public static void main(String[] args) {	
		StringBuilder sb = new StringBuilder("this");
		Object obj = new String(" is a string");
		System.out.println("Value after adding object:"+sb);
		System.out.println("Value after adding string:"+sb);
		long longVal = 123;
		System.out.println("Value after adding long:"+sb);
		boolean b = false;
		System.out.println("Value after adding boolean:"+sb);		


This example is a lot simpler than it looks. We just declared several data types and appended one by one to our character sequences to simulate the behavior of StringBuilder and append method.

Sample Output

Below is the sample output when you run the above example.

StringBuilder append() example output