字符类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