Friday, December 27, 2024
Google search engine
HomeLanguagesJavaStringBuffer appendCodePoint() Method in Java with Examples

StringBuffer appendCodePoint() Method in Java with Examples

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 = Lazyroar
       int cp = 156
Output: Lazyroar?

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

Example 1:

Java




// Java program to illustrate appendCodePoint() Method
// of StringBuffer class
 
// Importing required classes
import java.lang.*;
 
// Main class
public class GFG {
 
    // Main drive method
    public static void main(String[] args)
    {
 
        // Reading passed string
        StringBuffer sbf
            = new StringBuffer("Geeksforgeeks");
 
        // Printing the string
        System.out.println("String buffer = " + sbf);
 
        // Appending the CodePoint as String to the string
        // buffer
        sbf.appendCodePoint(65);
 
        // Printing the string again after
        // appending codePoint as string
        System.out.println("After appending CodePoint is = "
                           + sbf);
    }
}


Output: 

String buffer = Geeksforgeeks
After appending CodePoint is = GeeksforgeeksA

 

Example 2:

Java




// Java Program to Illustrate appendCodePoint() Method
// of StringBuffer class
 
// Importing required classes
import java.lang.*;
 
// Main class
public class GFG {
 
    // Main driver method
    public static void main(String[] args) {
 
        // Reading passed string by creating object of class
        StringBuffer sbf
            = new StringBuffer("Geeksforgeeks");
 
 
        System.out.println("String buffer = " + sbf);
 
        // Here it appends the CodePoint as
        // string to the string buffer
        sbf.appendCodePoint(54);
 
        System.out.println("After appending CodePoint is = "
                           + sbf);
    }
}


Output: 

String buffer = Geeksforgeeks
After appending CodePoint is = Geeksforgeeks6

 

Example 3:

Java




// Java program to illustrate appendCodePoint() Method
// of StringBuffer class
 
// Importing required classes
import java.lang.*;
 
// Main class
public class GFG {
 
    // Main driver method
    public static void main(String[] args)
    {
 
        // Reading passed string
        StringBuffer sbf
            = new StringBuffer("Geeksforgeeks");
 
        // Printing string on console
        System.out.println("String buffer = " + sbf);
 
        // Appending the codePoint as string
        // to the string buffer
        sbf.appendCodePoint(43);
 
        // Printing the string on console after
        // appending codepoint as string
        System.out.println("After appending CodePoint is = "
                           + sbf);
    }
}


Output: 

String buffer = Geeksforgeeks
After appending CodePoint is = Geeksforgeeks+

 

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments