Java StringBuilder 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 StringBuilder class.
appendCodePoint() Description
public StringBuilder 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 StringBuilder.
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 StringBuilder instance that contains the newly added chars.
Example 1: Append char at the end
public class JavaExample { public static void main(String[] args) { StringBuilder sb = new StringBuilder("Ato"); sb.appendCodePoint(90); //append 'Z' System.out.println(sb); //Print new Sequence } }
Output:
Example 2: Append Blush Smiley at the end of Sequence
public class JavaExample { public static void main(String[] args) { StringBuilder sb = new StringBuilder("Welcome"); sb.appendCodePoint(128522); //append Blush Smiley System.out.println(sb); } }
Output:
Recommended Posts
- Java StringBuilder codePointAt()
- Java StringBuilder subSequence()
- Java StringBuilder setCharAt()
- Java StringBuilder deleteCharAt()
References: official docs