Tuesday 12 March 2013

parseInt(String)


parseInt(String)


Description:
Parses the string argument as a signed integer in the radix specified by the second argument. The characters
in the string must all be digits of the specified radix (as determined by whether
Character.digit(char, int) returns a nonnegative value), except that the first character may be
an ASCII minus sign '-' ('\u002d') to indicate a negative value. The resulting integer value is
returned.
An exception of type NumberFormatException is thrown if any of the following situations occurs:
• The first argument is null or is a string of length zero.
• The radix is either smaller than Character.MIN_RADIX or larger than
Character.MAX_RADIX.
• Any character of the string is not a digit of the specified radix, except that the first character may be a
minus sign '-' ('\u002d') provided that the string is longer than length 1.
• The integer value represented by the string is not a value of type int.
Examples:
parseInt(“0”, 10) returns 0
parseInt(“473”, 10) returns 473
parseInt(“-0”, 10) returns 0
parseInt(“-FF”, 16) returns -255
parseInt(“1100110”, 2) returns 102
parseInt(“2147483647”, 10) returns 2147483647
parseInt(“-2147483648”, 10) returns -2147483648
parseInt(“2147483648”, 10) throws a NumberFormatException
parseInt(“99”, 8) throws a NumberFormatException
parseInt(“Kona”, 10) throws a NumberFormatException
parseInt(“Kona”, 27) returns 411787
Parameters:
s - the String containing the integer.
radix - the radix to be used.
Returns: the integer represented by the string argument in the specified radix.
Throws:
NumberFormatException - if the string does not contain a parsable integer.
parseInt(String)
Declaration:
public static int parseInt(java.lang.String s)
throws NumberFormatException
Description:
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(String, int) method.
Parameters:
s - a string.
Returns: the integer represented by the argument in decimal.
Throws:
NumberFormatException - if the string does not contain a parsable integer.

valueOf(String, int)
Declaration:
public static java.lang.Integer valueOf(java.lang.String s, int radix)
throws NumberFormatException
Description:
Returns a new Integer object initialized to the value of the specified String. The first argument is interpreted
as representing a signed integer in the radix specified by the second argument, exactly as if the arguments
were given to the parseInt(String, int) 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, radix))
Parameters:
s - the string to be parsed.
radix - the radix of the integer represented by string s
Returns: a newly constructed Integer initialized to the value represented by the string argument in the
specified radix.
Throws:
NumberFormatException - if the String cannot be parsed as an int.
valueOf(String)
Declaration:
public static java.lang.Integer valueOf(java.lang.String s)
throws NumberFormatException
Description:
Returns a new Integer object initialized to 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(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: a newly constructed Integer initialized to the value represented by the string argument.
Throws:
NumberFormatException - if the string cannot be parsed as an integer.
byteValue()
Declaration:
public byte byteValue()
Description:
Returns the value of this Integer as a byte.
Returns: the value of this Integer as a byte.
Since: JDK1.1


shortValue()

shortValue()
Declaration:
public short shortValue()
Description:
Returns the value of this Integer as a short.
Returns: the value of this Integer as a short.
Since: JDK1.1
intValue()
Declaration:
public int intValue()
Description:
Returns the value of this Integer as an int.
Returns: the int value represented by this object.
longValue()
Declaration:
public long longValue()
Description:
Returns the value of this Integer as a long.
Returns: the int value represented by this object that is converted to type long and the result of the
conversion is returned.
floatValue()
Declaration:
public float floatValue()
Description:
Returns the value of this Integer as a float.
Returns: the int value represented by this object is converted to type float and the result of the
conversion is returned.
Since: CLDC 1.1
doubleValue()
Declaration:
public double doubleValue()
Description:
Returns the value of this Integer as a double.
Returns: the int value represented by this object is converted to type double and the result of the
conversion is returned.
Since: CLDC 1.1



toString()
Declaration:
public java.lang.String toString()
Description:
Returns a String object representing this Integer’s value. The value is converted to signed decimal
representation and returned as a string, exactly as if the integer value were given as an argument to the
toString(int) method.
Overrides: toString in class Object
Returns: a string representation of the value of this object in base 10.
hashCode()
Declaration:
public int hashCode()
Description:
Returns a hashcode for this Integer.
Overrides: hashCode in class Object
Returns: a hash code value for this object, equal to the primitive int value represented by this Integer
object.
equals(Object)
Declaration:
public boolean equals(java.lang.Object obj)
Description:
Compares this object to the specified object. The result is true if and only if the argument is not null and
is an Integer object that contains the same int value as this object.
Overrides: equals in class Object
Parameters:
obj - the object to compare with.
Returns: true if the objects are the same; false otherwise.












No comments:

Post a Comment