Java StringBuffer appendCodePoint(int codePoint) Method appends string representation of the specified code point to this sequence. In this guide, we will discuss appendCodePoint() method with examples.
Syntax of appendCodePoint():
sb.appendCodePoint(90);
The above statement would append character āZā (Unicode code point 90) at the end of the sequence represented by the object of StringBuffer class.
appendCodePoint() Description
public StringBuffer appendCodePoint(int codePoint): This method appends the string representation of the specified code point value at the end of the sequence represented by object of StringBuffer.
This specified unicode code point can represent more than one characters so the length of the sequence after this append operation would be:
Initial length of sequence (sb.length()) + Character.charCount(codePoint)
appendCodePoint() Parameters
This method takes a single parameter:
- codePoint: A numeric value that represents a char array (string).
appendCodePoint() Return Value
- It returns a StringBuffer instance that contains the newly added chars.
Example 1: Append a char using Unicode code point
public class JavaExample { public static void main(String[] args) { StringBuffer sb = new StringBuffer("Zto"); System.out.println("Old String: "+sb); sb.appendCodePoint(89); //append 'Y' System.out.println("New String: "+sb); //Print new Sequence } }
Output:
Example 2: Append Emoji to StringBuffer
public class JavaExample { public static void main(String[] args) { StringBuffer sb = new StringBuffer("Hello "); sb.appendCodePoint(128522); //append Blush Smiley System.out.println(sb); } }
Output:
Example 3: Append Right Arrow
public class JavaExample { public static void main(String[] args) { StringBuffer sb = new StringBuffer("Next "); sb.appendCodePoint(8594); //append right arrow System.out.println(sb); } }
Output: