當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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 praogram 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 praogram 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)



相關用法


注:本文由純淨天空篩選整理自AmanSingh2210大神的英文原創作品 StringBuilder appendCodePoint() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。