Long valueOf(String s,int radix) 与 Long valueOf(String s)这两个重载方法,是
包装类Long 中的两个static 静态方法,基本的功能都是将参数String s 转换为对应的long型数(实际上是直接转换为Long 类型的数,然后因为自动拆箱的存在,可以直接当做long型数据来使用)。
具体的使用细则如下:
(1)valueOf(String s,int radix)
中文版的API中是下面这么说明的:
即:
public static Long valueOf(String s,
int radix)
throws NumberFormatException返回一个Long对象,该对象保存从指定的String String的值,并用第二个参数给出的基数进行解析。 第一个参数被解释为在第二个参数指定的基数中表示一个签名的long ,就好像参数被赋予parseLong(java.lang.String, int)方法一样。 结果是一个Long对象,表示由字符串指定的long值。
换句话说,该方法返回一个Long对象的值等于:
new Long(Long.parseLong(s, radix))
参数
s - 要解析的字符串
radix - 用于解释的基数 s
结果
一个保存由指定基数中的字符串参数表示的值的 Long对象。
异常
NumberFormatException - 如果 String不包含可解析的 long 。
英文版的API说明如下:
即:
public static Long valueOf(String s,
int radix)
throws NumberFormatException
Returns a Long object holding the value extracted from the specified String when parsed with the radix given by the second argument. The first argument is interpreted as representing a signed long in the radix specified by the second argument, exactly as if the arguments were given to the parseLong(java.lang.String, int) method. The result is a Long object that represents the long value specified by the string.
In other words, this method returns a Long object equal to the value of:
new Long(Long.parseLong(s, radix))
Parameters:
s - the string to be parsed
radix - the radix to be used in interpreting s
Returns:
a Long object holding the value represented by the string argument in the specified radix.
Throws:
NumberFormatException - If the String does not contain a parsable long.
(2)valueOf(String s)
中文版的API中是这么说明的:
即:
public static Long valueOf(String s)
throws NumberFormatException返回一个Long指定的Long的值的Long String 。
该参数被解释为表示一个有符号的十进制long ,正如参数被赋予parseLong(java.lang.String)方法一样。 结果是一个表示由字符串指定的整数值的Long对象。
换句话说,此方法返回一个Long对象的值等于:
new Long(Long.parseLong(s))
参数
s - 要解析的字符串。
结果
一个保存由string参数表示的值的 Long对象。
异常
NumberFormatException - 如果字符串不能被解析为 long 。
英文版的API如下:
即:
public static Long valueOf(String s)
throws NumberFormatException
Returns a Long object holding the value of the specified String. The argument is interpreted as representing a signed decimal long, exactly as if the argument were given to the parseLong(java.lang.String) method. The result is a Long object that represents the integer value specified by the string.
In other words, this method returns a Long object equal to the value of:
---->new Long(Long.parseLong(s))
Parameters:
s - the string to be parsed.
Returns:
a Long object holding the value represented by the string argument.
Throws:
NumberFormatException - If the string cannot be parsed as a long.