Java StringBuilder appendCodePoint()方法及示例

Java StringBuilder appendCodePoint()方法及示例

StringBuilder类appendCodePoint(int codePoint) 方法是用于将codePoint参数的字符串表示追加到这个序列中的内置方法。
参数被追加到这个StringBuilder内容中,对象的长度由Character.charCount(codePoint)增加。其效果与参数中的int值被转换为char数组,然后将该数组中的字符追加到这个字符序列中是一样的。
语法

public StringBuilder appendCodePoint(int codePoint)

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

// 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);
    }
}

输出

StringBuilder = GeeksforGeeks
Modified StringBuilder = GeeksforGeeksC

例2 :

// 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://docs.oracle.com/javase/7/docs/api/java/lang/StringBuilder.html#appendCodePoint(int)

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程