Name
Integer
Synopsis
Integer
provides an object wrapper for a Java
int
primitive value. The constructor initializes the
wrapper with an int
value, after which the object is
immutable. The value associated with an Integer
object
can be retrieved as a byte
, short
,
int
or long
using the
byteValue()
, shortValue()
,
intValue()
and longValue()
methods, respectively. If the value is too large to fit into a
byte or short, the high-order bits of the integer are truncated.
The static parseInt()
converts a numeric value held in a
String
into a primitive int
. The
single-argument variant of this method assumes that the string is encoded
in base 10; the two-argument variant can be used to specify a different number
base if necessary. A NumberFormatException
is thrown if
the String
does not represent a valid number in the given
number base. There are also two static valueOf
methods
that parse a string and return an Integer
object-- one
assumes that the String
is a base 10 number, the other
accepts a number base argument.
The zero-argument toString()
method returns a
String
representation of the value of the
Integer
encoded as a base 10 number. There is also a
static variant of this method that prints the value of a given
int
as a base 10 number, as well as a two-argument
variant that prints a value using digits from the number base
supplied as its second argument. The static toHexString()
,
toOctalString
and toBinaryString()
methods return a String
that represents the value of a
given int
as a ...
Get J2ME in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.