Java.lang.StringBuilder.append() Method


Advertisements


Description

The java.lang.StringBuilder.append(CharSequence s) method appends the specified character sequence.

Declaration

Following is the declaration for java.lang.StringBuilder.append() method

public StringBuilder append(CharSequence s)

Parameters

s − This is the character sequence to append. If s is null, then the four characters "null" are appended.

Return Value

This method returns a reference to this object.

Exception

IndexOutOfBoundsException − this is the exception thrown.

Example

The following example shows the usage of java.lang.StringBuilder.append() method.

package com.tutorialspoint;

import java.lang.*;

public class StringBuilderDemo {

   public static void main(String[] args) {
  
      StringBuilder str = new StringBuilder("amrood ");
      System.out.println("string = " + str);

      CharSequence cSeq = "admin";
      
      // appends the CharSequence
      str.append(cSeq);

      // print the StringBuilder after appending
      System.out.println("After append = " + str);
   }
} 

Let us compile and run the above program, this will produce the following result −

string = amrood
After append = amrood admin

java_lang_stringbuilder.htm

Advertisements