Java-lang-character-isdigit-codepoint

提供:Dev Guides
移動先:案内検索

Java.lang.Character.isDigit()メソッド

説明

  • java.lang.Character.isDigit(int codePoint)*は、指定された文字(Unicodeコードポイント)が数字かどうかを判断します。

getType(codePoint)によって提供される一般的なカテゴリタイプがDECIMAL_DIGIT_NUMBERである場合、文字は数字です。

数字を含むいくつかのユニコード文字範囲-

  • 「\ u0030」から「\ u0039」、ISO-LATIN-1の数字(「0」から「9」)
  • '\ u0660'〜 '\ u0669'、アラビア語-インド数字
  • '\ u06F0'〜 '\ u06F9'、拡張アラビア数字
  • 「\ u0966」から「\ u096F」、デーバナーガリー数字
  • 「\ uFF10」から「\ uFF19」、全角数字

他の多くの文字範囲にも数字が含まれています。

宣言

以下は* java.lang.Character.isDigit()*メソッドの宣言です

public static boolean isDigit(int codePoint)

パラメーター

*codePoint* -テストする文字(Unicodeコードポイント)

戻り値

このメソッドは、文字が数字の場合はtrueを返し、そうでない場合はfalseを返します。

例外

NA

次の例は、lang.Character.isDigit()メソッドの使用方法を示しています。

package com.finddevguides;

import java.lang.*;

public class CharacterDemo {

   public static void main(String[] args) {

     //create 2 int primitives cp1, cp2
      int cp1, cp2;

     //assign values to cp1, cp2
      cp1 = 0x06f8;
      cp2 = 0x0c12;

     //create 2 boolean primitives b1, b2
      boolean b1, b2;

     //assign isDigit results of ch1, ch2 to i1, i2
      b1 = Character.isDigit(cp1);
      b2 = Character.isDigit(cp2);

      String str1 = "cp1 represents a digit is " + b1;
      String str2 = "cp2 represents a digit is " + b2;

     //print b1, b2 values
      System.out.println( str1 );
      System.out.println( str2 );
   }
}

上記のプログラムをコンパイルして実行すると、次の結果が生成されます-

cp1 represents a digit is true
cp2 represents a digit is false