关于这个问题,相信java的API文档是最权威也是最正确的 ^_^ valueOf public static Long valueOf(String s, int radix) throws NumberFormatException当使用第二个参数给出的基数进行分析时,返回保持从指定 String 中提取的值的 Long 对象。第一个参数被解释为有符号的 long,基数由第二个参数指定,该值与用该参数作为参数的 parseLong(java.lang.String, int) 方法得到的值非常类似。结果是表示字符串指定的 long 值的 Long 对象。 换句话说,此方法返回一个 Long 对象,它的值等于: new Long(Long.parseLong(s, radix))参数: s - 要分析的字符串 radix - 将在解释 s 时使用的基数 返回: 保持由指定基数中的字符串参数表示的值的 Long 对象。 抛出: NumberFormatException - 如果 String 不包含可分析的 long。
多看源码和api parseLong: /** * Parses the string argument as a signed decimal * <code>long</code>. The characters in the string must all be * decimal digits, except that the first character may be an ASCII * minus sign <code>'-'</code> (<code>\u002D'</code>) to * indicate a negative value. The resulting <code>long</code> * value is returned, exactly as if the argument and the radix * <code>10</code> were given as arguments to the {@link * #parseLong(java.lang.String, int)} method. * <p> * Note that neither the character <code>L</code> * (<code>'\u004C'</code>) nor <code>l</code> * (<code>'\u006C'</code>) is permitted to appear at the end * of the string as a type indicator, as would be permitted in * Java programming language source code. * * @param s a <code>String</code> containing the <code>long</code> * representation to be parsed * @return the <code>long</code> represented by the argument in * decimal. * @exception NumberFormatException if the string does not contain a * parsable <code>long</code>. */ Long.valueOf: /** * Returns a <code>Long</code> object holding the value * of the specified <code>String</code>. The argument is * interpreted as representing a signed decimal <code>long</code>, * exactly as if the argument were given to the {@link * #parseLong(java.lang.String)} method. The result is a * <code>Long</code> object that represents the integer value * specified by the string. * <p> * In other words, this method returns a <code>Long</code> object * equal to the value of: * * <blockquote><pre> * new Long(Long.parseLong(s)) * </pre></blockquote> * * @param s the string to be parsed. * @return a <code>Long</code> object holding the value * represented by the string argument. * @exception NumberFormatException If the string cannot be parsed * as a <code>long</code>. */
不好意思,刚发现贴错方法了。 valueOf public static Long valueOf(String s) throws NumberFormatException返回保持指定 String 的值的 Long 对象。该参数被解释为表示一个有符号的十进制 long,该值与用该参数作为参数的 parseLong(java.lang.String) 方法得到的值非常相似。结果是表示由字符串指定的整数值的 Long 对象。 换句话说,此方法返回一个 Long 对象,它的值等于: new Long(Long.parseLong(s))
参数: s - 要分析的字符串。 返回: 包含由字符串参数表示的值的 Long 对象。 抛出: NumberFormatException - 如果不能将字符串分析为 long。
一样的,看源码:public static Long valueOf(String s, int radix) throws NumberFormatException { return new Long(parseLong(s, radix)); }
valueOf
public static Long valueOf(String s,
int radix)
throws NumberFormatException当使用第二个参数给出的基数进行分析时,返回保持从指定 String 中提取的值的 Long 对象。第一个参数被解释为有符号的 long,基数由第二个参数指定,该值与用该参数作为参数的 parseLong(java.lang.String, int) 方法得到的值非常类似。结果是表示字符串指定的 long 值的 Long 对象。
换句话说,此方法返回一个 Long 对象,它的值等于: new Long(Long.parseLong(s, radix))参数:
s - 要分析的字符串
radix - 将在解释 s 时使用的基数
返回:
保持由指定基数中的字符串参数表示的值的 Long 对象。
抛出:
NumberFormatException - 如果 String 不包含可分析的 long。
parseLong:
/**
* Parses the string argument as a signed decimal
* <code>long</code>. The characters in the string must all be
* decimal digits, except that the first character may be an ASCII
* minus sign <code>'-'</code> (<code>\u002D'</code>) to
* indicate a negative value. The resulting <code>long</code>
* value is returned, exactly as if the argument and the radix
* <code>10</code> were given as arguments to the {@link
* #parseLong(java.lang.String, int)} method.
* <p>
* Note that neither the character <code>L</code>
* (<code>'\u004C'</code>) nor <code>l</code>
* (<code>'\u006C'</code>) is permitted to appear at the end
* of the string as a type indicator, as would be permitted in
* Java programming language source code.
*
* @param s a <code>String</code> containing the <code>long</code>
* representation to be parsed
* @return the <code>long</code> represented by the argument in
* decimal.
* @exception NumberFormatException if the string does not contain a
* parsable <code>long</code>.
*/
Long.valueOf:
/**
* Returns a <code>Long</code> object holding the value
* of the specified <code>String</code>. The argument is
* interpreted as representing a signed decimal <code>long</code>,
* exactly as if the argument were given to the {@link
* #parseLong(java.lang.String)} method. The result is a
* <code>Long</code> object that represents the integer value
* specified by the string.
* <p>
* In other words, this method returns a <code>Long</code> object
* equal to the value of:
*
* <blockquote><pre>
* new Long(Long.parseLong(s))
* </pre></blockquote>
*
* @param s the string to be parsed.
* @return a <code>Long</code> object holding the value
* represented by the string argument.
* @exception NumberFormatException If the string cannot be parsed
* as a <code>long</code>.
*/
valueOf
public static Long valueOf(String s)
throws NumberFormatException返回保持指定 String 的值的 Long 对象。该参数被解释为表示一个有符号的十进制 long,该值与用该参数作为参数的 parseLong(java.lang.String) 方法得到的值非常相似。结果是表示由字符串指定的整数值的 Long 对象。
换句话说,此方法返回一个 Long 对象,它的值等于: new Long(Long.parseLong(s))
参数:
s - 要分析的字符串。
返回:
包含由字符串参数表示的值的 Long 对象。
抛出:
NumberFormatException - 如果不能将字符串分析为 long。
return new Long(parseLong(s, radix));
}