Java Reference
In-Depth Information
8.4.
Number
The
Number
class is an abstract class extended by all wrapper classes that
represent primitive numeric types:
Byte
,
Short
,
Integer
,
Long
,
Float
, and
Double
.
The abstract methods of
Number
return the value of the object converted
to any of the numeric types:
public byte
byteValue()
public short
shortValue()
public int
intValue()
public long
longValue()
public float
floatValue()
public double
doubleValue()
Each extended
Number
class overrides these methods to convert its own
type to any of the others under the same rules used for an explicit cast.
For example, given a
Float
object with the value
32.87
, the return value
of
intValue
on the object would be
32
, just as "
(int)32.87
" would be
32
.
8.4.1. The Integer Wrappers
The classes
Byte
,
Short
,
Integer
, and
Long
extend
Number
to represent the
corresponding integer types as classes. In addition to the standard
Num-
ber
methods, each of the integer wrapper classes supports the following
methods:
public static
type
parse
Type
(String str, int radix)
Converts the string
str
into a numeric value of the specified
type
, using the given radix. For example,
In-
teger.parseInt("1010",2)
returns 10, and
In-
teger.parseInt("-1010",2)
returns 10. The characters in the