Java.lang.StringBuffer.codePointBefore() 方法
描述
java.lang.StringBuffer.codePointBefore() 方法返回指定 index 之前的字符(Unicode 代码点)。索引指的是 char 值(Unicode 代码单元)和 范围从 1 到 length()。
声明
以下是 java.lang.StringBuffer.codePointBefore() 方法的声明。
public int codePointBefore(int index)
参数
index − 这是应返回的代码点之后的索引。
返回值
此方法返回给定索引之前的 Unicode 代码点值。
异常
NA
示例
下面的例子展示了 java.lang.StringBuffer.codePointBefore() 方法的使用。
package com.tutorialspoint;
import java.lang.*;
public class StringBufferDemo {
public static void main(String[] args) {
StringBuffer buff = new StringBuffer("TUTORIALS");
System.out.println("buffer = " + buff);
// returns the codepoint before index 3
int retval = buff.codePointBefore(3);
System.out.println("Character(unicode point) = " + retval);
buff = new StringBuffer("amrood admin ");
System.out.println("buffer = " + buff);
// returns the codepoint before index 6
retval = buff.codePointBefore(6);
System.out.println("Character(unicode point) = " + retval);
}
}
让我们编译并运行上面的程序,这将产生下面的结果 −
buffer = TUTORIALS Character(unicode point) = 84 buffer = amrood admin Character(unicode point) = 100

