Java StringBuffer int codePointCount(int index1,int index 2)方法,带示例
StringBuffer类intcodePointCount(intindex1,intindex2)
包java.lang.StringBuffer.codePointCount(intindex)中提供了此方法。
此方法用于在方法的指定索引范围内返回Unicode代码点的数量(即,它返回位于索引1和索引2之间的所有Unicode代码点的数量)。
索引范围将从0到length()-1。
此方法不会引发异常。
语法:
int codePointCount(int index1 , int index2){
}参数:
我们在StringBuffer的方法中传递了两个对象,即index1和index2。
返回值:
此方法的返回类型为int,这意味着此方法返回index1和index2之间的所有Unicode代码点的计数,并且代码点的值为数字格式。
Java程序演示codePointCount()方法示例
import java.lang.StringBuffer;
public class StringBufferClass {
public static void main(String[] args) {
StringBuffer sb = new StringBuffer("Java is a pure OOPS");
//使用codePointCount(intindex1,intindex2)
//它将返回Unicode代码点所在的数量
//在索引1和索引2之间
int codepointcount = sb.codePointCount(2, 8);
//后显示结果
System.out.println("The result will be after implementing method codePointCount(2 , 8) is :" + codepointcount);
sb = new StringBuffer("Current Version of Java is 8");
//使用codePointCount(intindex1,intindex2)
//它将返回Unicode代码点所在的数量
//在索引1和索引2之间
//后显示结果
System.out.println("The result will be after implementing method codePointCount(3,9) is :" + sb.codePointCount(3, 9));
}
}输出结果
D:\Programs>javac StringBufferClass.java D:\Programs>java StringBufferClass The result will be after implementing method codePointCount(2 , 8) is :6 The result will be after implementing method codePointCount(3,9) is :6