StringBuffer appendCodePoint() Method in Java with Examples

Course Curriculum

StringBuffer appendCodePoint() Method in Java with Examples

StringBuffer appendCodePoint() Method in Java with Examples

The java.lang.StringBuffer.appendCodePoint(int cp)is the method which appends the string representation of the codePoint argument to this sequence.

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 Value : The method returns this object after appending the string represented by the codepoint.

Examples :

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

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

Explanation:
Because 65 is the ASCII value for 'A' and
156 is the ASCII value for '?'
Below programs illustrate the java.lang.StringBuffer.appendCodePoint(int cp) method:
Program 1:

// Java praogram to illustrate the
// java.lang.StringBuffer.appendCodePoint(int cp)
import java.lang.*;

public class Prutor {

public static void main(String[] args)
{

StringBuffer sbf = new StringBuffer("PrutordotAi");
System.out.println("String buffer = " + sbf);

// Here it appends the CodePoint as
// String to the string buffer
sbf.appendCodePoint(65);
System.out.println("After appending CodePoint is = " + sbf);
}
}
Output:
String buffer = PrutordotAi
After appending CodePoint is = PrutordotAiA
Program 2:

// Java praogram to illustrate the
// java.lang.StringBuffer.appendCodePoint(int cp)
import java.lang.*;

public class Prutor {

public static void main(String[] args)
{

StringBuffer sbf = new StringBuffer("PrutordotAi");
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 = PrutordotAi
After appending CodePoint is = PrutordotAi6
Program 3:

// Java praogram to illustrate the
// java.lang.StringBuffer.appendCodePoint(int cp)
import java.lang.*;

public class Prutor {

public static void main(String[] args)
{

StringBuffer sbf = new StringBuffer("PrutordotAi");
System.out.println("String buffer = " + sbf);

// Here it appends the CodePoint as
// string to the string buffer
sbf.appendCodePoint(43);

System.out.println("After appending CodePoint is = " + sbf);
}
}
Output:
String buffer = PrutordotAi
After appending CodePoint is = PrutordotAi+

Enum with Customized Value in Java (Prev Lesson)
(Next Lesson) Variables in Java
', { 'anonymize_ip': true });