Java字符类toString()方法及示例

字符类toString()方法 (Character class toString() method)

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

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

  • toString() method is used to return the String object denoting the given Char value.

    toString()方法用于返回表示给定Char值的String对象。

  • toString() method does not throw an exception at the time of conversion an object to a string.

    将对象转换为字符串时, toString()方法不会引发异常。

Syntax:

句法:

    public String toString(Char value);

Parameter(s):

参数:

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

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

Return value:

返回值:

The return type of this method is String, it returns a string representation of the given Char value.

此方法的返回类型为String ,它返回给定Char值的字符串表示形式。

Example:

例:

// Java program to demonstrate the example 
// of String toString(Char value) method of Character class

public class ToStringOfCharacter {
    public static void main(String[] args) {
        // It returns P
        String result1 = Character.toString('P');

        // It returns p 
        String result2 = Character.toString('p');

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

Output

输出量

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


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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值