Java StringBuffer codePointAt()方法

java.lang.StringBuffer.codePointAt() 方法返回指定索引处的字符(Unicode代码点)。该指数是指由0 到(Unicode代码单元)范围length()- 1的char值。

1 语法

public int codePointAt(int index)

2 参数

index : 这是索引。

3 返回值

此方法返回字符索引处的代码点值。

4 示例 

package com.yiidian;

/**
 * 一点教程网: http://www.yiidian.com
 */
/**
 * Java StringBuffer codePointAt()方法
 */
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 at index 5
    int retval = buff.codePointAt(5);
    System.out.println("Character(unicode point) = " + retval);
    
    buff = new StringBuffer("amrood admin ");
    System.out.println("buffer = " + buff);
    // returns the codepoint at index 6 i.e whitespace character
    retval = buff.codePointAt(6);
    System.out.println("Character(unicode point) = " + retval);
  }
}

输出结果为:

buffer = TUTORIALS
Character(unicode point) = 73
buffer = amrood admin
Character(unicode point) = 32

 

热门文章

优秀文章