当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java StringBuffer appendCodePoint()用法及代码示例


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

用法:

public StringBuffer appendCodePoint(int cp)

参数:该方法接受整数类型的单个参数cp,表示Unicode代码点。


返回值:该方法在附加由代码点表示的字符串之后返回此对象。

例子:

Input: StringBuffer = Apple
       int cp = 65
Output: AppleA 

Input: StringBuffer = GeeksforGeeks
       int cp = 156
Output: GeeksforGeeks?

Explanation:
Because 65 is the ASCII value for 'A' and
156 is the ASCII value for '?'

以下示例程序旨在说明java.lang.StringBuffer.appendCodePoint(int cp)方法:
示例1:

// Java praogram to illustrate the 
// java.lang.StringBuffer.appendCodePoint(int cp) 
import java.lang.*; 
  
public class Geeks { 
  
    public static void main(String[] args) 
    { 
  
        StringBuffer sbf = new StringBuffer("Geeksforgeeks"); 
        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 = Geeksforgeeks
After appending CodePoint is = GeeksforgeeksA

示例2:

// Java praogram to illustrate the 
// java.lang.StringBuffer.appendCodePoint(int cp) 
import java.lang.*; 
  
public class Geeks { 
  
    public static void main(String[] args) 
    { 
  
        StringBuffer sbf = new StringBuffer("Geeksforgeeks"); 
        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 = Geeksforgeeks
After appending CodePoint is = Geeksforgeeks6

示例3:

// Java praogram to illustrate the 
// java.lang.StringBuffer.appendCodePoint(int cp) 
import java.lang.*; 
  
public class Geeks { 
  
    public static void main(String[] args) 
    { 
  
        StringBuffer sbf = new StringBuffer("Geeksforgeeks"); 
        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 = Geeksforgeeks
After appending CodePoint is = Geeksforgeeks+


相关用法


注:本文由纯净天空筛选整理自ankita_chowrasia大神的英文原创作品 StringBuffer appendCodePoint() Method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。