java.lang.Character.isUpperCase(int codePoint)方法範例


java.lang.Character.isUpperCase(int codePoint) 確定指定字元(Unicode程式碼點)是否為一個大寫字母。

字元是大寫,如果它的一般類別型別,通過getType(codePoint)所提供的UPPERCASE_LETTER,或屬性為Other_Uppercase Unicode標準的定義。

宣告

以下是java.lang.Character.isUpperCase()方法的宣告

public static boolean isUpperCase(int codePoint)

引數

  • codePoint - 要進行測試的字元(Unicode程式碼點)

返回值

如果字元是大寫此方法返回true,否則為false。

異常

  • NA

例子

下面的例子顯示lang.Character.isUpperCase()方法的使用。

package com.yiibai;

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 = 0x004a; // represents J
      cp2 = 0x0071; // represents x

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

      // check if cp1, cp2 are uppercase and assign results to b1, b2
      b1 = Character.isUpperCase(cp1);
      b2 = Character.isUpperCase(cp2);

      String str1 = "cp1 is uppercase character is " + b1;
      String str2 = "cp2 is uppercase character is " + b2;

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

讓我們來編譯和執行上面的程式,這將產生以下結果:

cp1 is uppercase character is true
cp2 is uppercase character is false