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)
相关用法
- Java StringBuffer appendCodePoint()用法及代码示例
- Java StringBuilder append()用法及代码示例
- Java StringBuilder trimToSize()用法及代码示例
- Java StringBuilder substring()用法及代码示例
- Java StringBuilder lastIndexOf()用法及代码示例
- Java StringBuilder toString()用法及代码示例
- Java StringBuilder indexOf()用法及代码示例
- Java StringBuilder offsetByCodePoints()用法及代码示例
- Java Matcher appendTail(StringBuilder)用法及代码示例
- Java Matcher appendReplacement(StringBuilder, String)用法及代码示例
- Java StringBuilder subSequence()用法及代码示例
- Java StringBuilder length()用法及代码示例
- Java StringBuilder getChars()用法及代码示例
- Java StringBuilder charAt()用法及代码示例
注:本文由纯净天空筛选整理自AmanSingh2210大神的英文原创作品 StringBuilder appendCodePoint() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。