StringBuffer appendCodePoint() Method in Java with Examples (original) (raw)

Last Updated : 08 Jun, 2022

appendCodePoint() method of StringBuffer class appends the string representation of the codePoint argument to this sequence for which we require pre-requisite knowledge of ASCII table as then only we will be able to perceive output why the specific literal is being appended as there is already an integer value been assigned.

--> appendCodePoint() Method --> StringBuffer Class --> java.lang Package

Syntax:

public StringBuffer appendCodePoint(int cp)

Parameters: The method accepts a single parameter cp of integer type and refers to the Unicode code point.

Return Type: The method returns this object after appending the string represented by the codepoint.

Illustrations:

Input : StringBuffer = Apple int cp = 65 Output: AppleA

Input : StringBuffer = GeeksforGeeks int cp = 156 Output: GeeksforGeeks?

Explanation: Because 65 is the ASCII value for ‘A’ and 156 is the ASCII value for ‘?’

Example 1:

Java

import java.lang.*;

public class GFG {

`` public static void main(String[] args)

`` {

`` StringBuffer sbf

`` = new StringBuffer( "Geeksforgeeks" );

`` System.out.println( "String buffer = " + sbf);

`` sbf.appendCodePoint( 65 );

`` System.out.println( "After appending CodePoint is = "

`` + sbf);

`` }

}

Output:

String buffer = Geeksforgeeks After appending CodePoint is = GeeksforgeeksA

Example 2:

Java

import java.lang.*;

public class GFG {

`` public static void main(String[] args) {

`` StringBuffer sbf

`` = new StringBuffer( "Geeksforgeeks" );

`` System.out.println( "String buffer = " + sbf);

`` sbf.appendCodePoint( 54 );

`` System.out.println( "After appending CodePoint is = "

`` + sbf);

`` }

}

Output:

String buffer = Geeksforgeeks After appending CodePoint is = Geeksforgeeks6

Example 3:

Java

import java.lang.*;

public class GFG {

`` public static void main(String[] args)

`` {

`` StringBuffer sbf

`` = new StringBuffer( "Geeksforgeeks" );

`` System.out.println( "String buffer = " + sbf);

`` sbf.appendCodePoint( 43 );

`` System.out.println( "After appending CodePoint is = "

`` + sbf);

`` }

}

Output:

String buffer = Geeksforgeeks After appending CodePoint is = Geeksforgeeks+