📜  Java中的 StringBuilder appendCodePoint() 方法及示例

📅  最后修改于: 2022-05-13 01:55:21.473000             🧑  作者: Mango

Java中的 StringBuilder appendCodePoint() 方法及示例

StringBuilder 类appendCodePoint(int codePoint)方法是用于将 codePoint 参数的字符串表示附加到此序列的内置方法。
参数附加到此 StringBuilder 内容,并且对象的长度增加了字符.charCount(codePoint)。效果与将参数中的 int 值转换为 char 数组并将该数组中的字符附加到此字符序列中的效果相同。
句法:

public StringBuilder appendCodePoint(int codePoint)

参数:该方法只接受一个参数codePoint ,它是int类型的值是指一个Unicode码位。
返回值:此方法返回对该对象的引用。
下面的程序说明了Java.lang.StringBuilder.appendCodePoint() 方法:
示例 1:

Java
// Java program to illustrate the
// appendCodePoint(int codePoint)
 
import java.lang.*;
 
public class Geeks {
    public static void main(String[] args)
    {
 
        // create StringBuilder object
        StringBuilder
            str
            = new StringBuilder("GeeksforGeeks");
        System.out.println("StringBuilder = "
                           + str);
 
        // Append 'C'(67) to the String
        str.appendCodePoint(67);
 
        // Print the modified String
        System.out.println("Modified StringBuilder = "
                           + str);
    }
}


Java
// Java program to illustrate the
// appendCodePoint(int codePoint)
 
import java.lang.*;
 
public class Geeks {
    public static void main(String[] args)
    {
 
        // create StringBuilder object
        StringBuilder
            str
            = new StringBuilder("GeeksforGeeks");
        System.out.println("StringBuilder = "
                           + str);
 
        // Append ', '(44) to the String
        str.appendCodePoint(44);
 
        // Print the modified String
        System.out.println("Modified StringBuilder = "
                           + str);
    }
}


输出:
StringBuilder = GeeksforGeeks
Modified StringBuilder = GeeksforGeeksC

示例 2:

Java

// Java program to illustrate the
// appendCodePoint(int codePoint)
 
import java.lang.*;
 
public class Geeks {
    public static void main(String[] args)
    {
 
        // create StringBuilder object
        StringBuilder
            str
            = new StringBuilder("GeeksforGeeks");
        System.out.println("StringBuilder = "
                           + str);
 
        // Append ', '(44) to the String
        str.appendCodePoint(44);
 
        // Print the modified String
        System.out.println("Modified StringBuilder = "
                           + str);
    }
}
输出:
StringBuilder = GeeksforGeeks
Modified StringBuilder = GeeksforGeeks,

参考资料: https: Java/lang/StringBuilder.html#appendCodePoint(int)