touppercase_Java字符类toUpperCase()方法与示例

本文详细介绍了Java.lang包中的toUpperCase()方法,该方法用于将给定的字符值转换为其大写形式,无论输入字符是否已经是大写。文章通过示例展示了如何使用此方法,并解释了其语法和返回值。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

touppercase

字符类的toUpperCase()方法 (Character class toUpperCase() method)

  • toUpperCase() method is available in java.lang package.

    toUpperCase()方法在java.lang包中可用。

  • toUpperCase() method is used to return the uppercase character of the given char value.

    toUpperCase()方法用于返回给定char值的大写字符。

  • toUpperCase() method does not throw an exception at the time of representing lowercase character to uppercase character or uppercase to the uppercase character.

    在将小写字符表示为大写字符或将大写字符表示为大写字符时, toUpperCase()方法不会引发异常。

Syntax:

句法:

    public char toUpperCase (Char value);

Parameter(s):

参数:

  • Char value – represents the char value to be converted.

    字符值 –表示要转换的字符值。

Return value:

返回值:

The return type of this method is char, it returns the uppercase conversion of the given char value.

此方法的返回类型为char ,它返回给定char值的大写转换。

Example:

例:

// 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);
    }
}

Output

输出量

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


翻译自: https://www.includehelp.com/java/character-class-touppercase-method-with-example.aspx

touppercase

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值