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

📅  最后修改于: 2020-02-12 14:46:26             🧑  作者: Mango

java.lang.StringBuffer.appendCodePoint(int cp)是将codePoint参数的字符串表示形式附加到此序列的方法。
语法 :

public StringBuffer appendCodePoint(int cp)

参数:该方法接受整数类型的单个参数cp,并引用Unicode代码。
返回值:该方法在附加由代码点表示的字符串之后返回此对象。
例子 :

输入:
输入: StringBuffer = Apple
       int cp = 65
输出: AppleA
输入: StringBuffer = 芒果文档
       int cp = 156
输出: 芒果文档?
说明:
因为65是'A'的ASCII值,
156是'?'的ASCII值
下面的程序说明了java.lang.StringBuffer.appendCodePoint(int cp)方法:
程序1:
// Java程序,展示java.lang.StringBuffer.appendCodePoint(int cp)
import java.lang.*;
public class 芒果 {
    public static void main(String[] args)
    {
        StringBuffer sbf = new StringBuffer("芒果文档");
        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);
    }
}
输出:
String buffer = 芒果文档
After appending CodePoint is = 芒果文档A
程式2:
// Java程序,展示java.lang.StringBuffer.appendCodePoint(int cp)
import java.lang.*;
public class 芒果 {
    public static void main(String[] args)
    {
        StringBuffer sbf = new StringBuffer("芒果文档");
        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);
    }
}
输出:
String buffer = 芒果文档
After appending CodePoint is = 芒果文档6
程式3:
// Java程序,展示java.lang.StringBuffer.appendCodePoint(int cp)
import java.lang.*;
public class 芒果 {
    public static void main(String[] args)
    {
        StringBuffer sbf = new StringBuffer("芒果文档");
        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);
    }
}
输出
String buffer = 芒果文档
After appending CodePoint is = 芒果文档+