본문 바로가기
Development/Java

What is the defference between Integer.parseInt and Integer.valueOf

by Sonagiya 2013. 5. 1.
반응형

parseInt
public static int parseInt(String s)
                    throws NumberFormatException
Parses the string argument as a signed decimal integer. The characters in the string must all be decimal digits, except that the first character may be an ASCII minus sign '-' ('\u002D') to indicate a negative value. The resulting integer value is returned, exactly as if the argument and the radix 10 were given as arguments to the parseInt(java.lang.String, int) method.

Parameters:
s - a String containing the int representation to be parsed
Returns:
the integer value represented by the argument in decimal.
Throws:
NumberFormatException - if the string does not contain a parsable integer.
___________________________________________________________________________

valueOf

public static Integer valueOf(String s)
                       throws NumberFormatException
Returns an Integer object holding the value of the specified String. The argument is interpreted as representing a signed decimal integer, exactly as if the argument were given to the parseInt(java.lang.String) method. The result is an Integer object that represents the integer value specified by the string.

In other words, this method returns an Integer object equal to the value of:

new Integer(Integer.parseInt(s))

Parameters:
s - the string to be parsed.
Returns:
an Integer object holding the value represented by the string argument.
Throws:
NumberFormatException - if the string cannot be parsed as an integer.

반응형

'Development > Java' 카테고리의 다른 글

Unable to load default SVN Client 발생 시.  (0) 2014.11.10
call by reference vs call by pointer.  (0) 2014.02.12

댓글