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


Java Character toUpperCase()用法及代碼示例

Character類toUpperCase()方法

  • toUpperCase() 方法可在java.lang包。
  • toUpperCase() 方法用於返回給定的大寫字符char值。
  • toUpperCase() 方法在將小寫字符表示為大寫字符或將大寫字符表示為大寫字符時不拋出異常。

用法:

    public char toUpperCase (Char value);

參數:

  • Char value– 表示要轉換的字符值。

返回值:

這個方法的返回類型是char,它返回給定字符值的大寫轉換。

例:

// Java program to demonstrate the example 
// of char toUpperCase (Char value) method of Character class	

public class ToUpperCaseOfCharacterClass {
    public static void main(String[] args) {
        // It returns P because the passing character is 
        // already in UpperCase
        char result1 = Character.toUpperCase('P');

        // It returns P because the passing character will
        // be converted to UpperCase by using toUpperCase()
        char result2 = Character.toUpperCase('p');

        // Display values of result1 , result2
        System.out.println("Character.toUpperCase('P'):" + result1);
        System.out.println("Character.toUpperCase('p'):" + result2);
    }
}

輸出

Character.toUpperCase('P'):P
Character.toUpperCase('p'):P


相關用法


注:本文由純淨天空篩選整理自Preeti Jain大神的英文原創作品 Java Character class toUpperCase() method with example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。