
写这篇博客的初衷是:今天百度查了下char转String的问题,一位老兄的博客里面写着调用char类型的toString方法。
java新版JDK里面关于一些常见类型转String的静态方法:
static String | valueOf(boolean b) Returns the string representation of the boolean argument. |
|---|---|
static String | valueOf(char c) Returns the string representation of the char argument. |
static String | valueOf(char[] data) Returns the string representation of the char array argument. |
static String | valueOf(char[] data, int offset, int count) Returns the string representation of a specific subarray of the char array argument. |
static String | valueOf(double d) Returns the string representation of the double argument. |
static String | valueOf(float f) Returns the string representation of the float argument. |
static String | valueOf(int i) Returns the string representation of the int argument. |
static String | valueOf(long l) Returns the string representation of the long argument. |
static String | valueOf(Object obj) Returns the string representation of the Object argument. |
其实了解java基础的人都应该知道toString是所有Object对象的一个方法,但是char属于基本类型,不属于类范畴!!
估计这位老兄说的应该是char类型的包装器类型Character的toString方法吧,这个方法的用法如下,一看便明白:
static StringtoString(char c)
Returns a String object representing the specified char.