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


Java Java.lang.Character.codePointAt()用法及代碼示例


描述

這個java.lang.Character.codePointAt(char[ ] a, int index, int limit)返回 char 數組給定索引處的代碼點,其中隻能使用索引小於 limit 的數組元素。

如果char數組中給定索引處的char值在高代理範圍內,後麵的索引小於限製,並且後麵索引處的char值在低代理範圍內,則補充碼點對應於這個代理對被返回。否則,返回給定索引處的 char 值。

聲明

以下是聲明java.lang.Character.codePointAt()方法

public static int codePointAt(char[] a, int index, int limit)

參數

  • a- 字符數組

  • index- 要轉換的字符數組中字符值(Unicode 代碼單元)的索引

  • limit− 可在 char 數組中使用的最後一個數組元素之後的索引

返回值

此方法返回給定索引處的 Unicode 代碼點。

異常

  • NullPointerException- 如果 a 為空。

  • IndexOutOfBoundsException- 如果 index 參數為負數或不小於 limit 參數,或者如果 limit 參數為負數或大於 char 數組的長度。

示例

下麵的例子展示了 lang.Character.codePointAt() 方法的用法。

package com.tutorialspoint;

import java.lang.*;

public class CharacterDemo {

   public static void main(String[] args) {

      // create a char array c and assign values
      char[] c = new char[] { 'a', 'b', 'c', 'd', 'e' };

      // create and assign value to inetgers index, limit
      int index  = 1, limit = 3;

      // create an int res
      int res;

      // assign result of codePointAt on array c at index to res using limit
      res = Character.codePointAt(c, index, limit);

      String str = "Unicode code point is " + res;

      // print res value
      System.out.println( str );
   }
}

讓我們編譯並運行上麵的程序,這將產生以下結果 -

Unicode code point is 98

相關用法


注:本文由純淨天空篩選整理自 Java.lang.Character.codePointAt() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。