java::lang::Integer Class Reference

Inheritance diagram for java::lang::Integer:

Inheritance graph
java::lang::Numberjava::lang::Objectjava::lang::Interfacejava::lang::Comparable
[legend]
Collaboration diagram for java::lang::Integer:

Collaboration graph
java::lang::Numberjava::lang::Objectjava::lang::Interfacejava::lang::Comparable
[legend]

List of all members.


Detailed Description

The Integer class wraps a value of the primitive type int in an object.

An object of type Integer contains a single field whose type is int.

In addition, this class provides several methods for converting an int to a String and a String to an int, as well as other constants and methods useful when dealing with an int.

Author:
Yuh-Jye Chang
Version:
1.64, 02/09/01
Since:
JDK1.0

Public Member Functions

 Integer (jint _value=0)
 Constructs a newly allocated Integer object that represents the primitive int argument.
 operator jint & ()
virtual jbyte byteValue () const
 Returns the value of this Integer as a byte.
virtual jshort shortValue () const
 Returns the value of this Integer as a short.
virtual jint intValue () const
 Returns the value of this Integer as an int.
virtual jlong longValue () const
 Returns the value of this Integer as a long.
virtual jfloat floatValue () const
 Returns the value of this Integer as a float.
virtual jdouble doubleValue () const
 Returns the value of this Integer as a double.
virtual jboolean equals (const Object &src) const
 Compares this object to the specified object.
virtual jint hashCode () const
 Returns a hashcode for this Integer.
virtual jint compareTo (const Object &src) const
 Compares this Integer to another Object.
virtual String toString () const
 Returns a String object representing this Integer's value.

Static Public Member Functions

static String toString (jint i, jint radix=10)
 Creates a string representation of the first argument in the radix specified by the second argument.
static String toHexString (jint i)
 Creates a string representation of the integer argument as an unsigned integer in base 16.
static String toOctalString (jint i)
 Creates a string representation of the integer argument as an unsigned integer in base 8.
static String toBinaryString (jint i)
 Creates a string representation of the integer argument as an unsigned integer in base 2.
static jint parseInt (const String &s, jint radix=10)
 Parses the string argument as a signed integer in the radix specified by the second argument.
static const Integer valueOf (const String &s, jint radix=10)
 Returns a new Integer object initialized to the value of the specified String.

Static Public Attributes

static const jint MIN_VALUE
 The smallest value of type int.
static const jint MAX_VALUE
 The largest value of type int.

Constructor & Destructor Documentation

java::lang::Integer::Integer ( jint  _value = 0  ) 

Constructs a newly allocated Integer object that represents the primitive int argument.

Parameters:
value the value to be represented by the Integer.


Member Function Documentation

static String java::lang::Integer::toString ( jint  i,
jint  radix = 10 
) [static]

Creates a string representation of the first argument in the radix specified by the second argument.

If the radix is smaller than Character.MIN_RADIX or larger than Character.MAX_RADIX, then the radix 10 is used instead.

If the first argument is negative, the first element of the result is the ASCII minus character '-' ('\u002d'). If the first argument is not negative, no sign character appears in the result.

The remaining characters of the result represent the magnitude of the first argument. If the magnitude is zero, it is represented by a single zero character '0' ('&#92;u0030'); otherwise, the first character of the representation of the magnitude will not be the zero character. The following ASCII characters are used as digits: <blockquote>

   0123456789abcdefghijklmnopqrstuvwxyz
 
</blockquote> These are '&#92;u0030' through '&#92;u0039' and '&#92;u0061' through '&#92;u007a'. If the radix is N, then the first N of these characters are used as radix-N digets in the order shown. Thus, the digits for hexadecimal (radix 16) are 0123456789abcdef. If uppercase letters are desired, the java.lang.String#toUpperCase() method may be called on the result: <blockquote>
 Integer.toString(n, 16).toUpperCase()
 
</blockquote>

Parameters:
i an integer.
radix the radix.
Returns:
a string representation of the argument in the specified radix.

static String java::lang::Integer::toHexString ( jint  i  )  [static]

Creates a string representation of the integer argument as an unsigned integer in base 16.

The unsigned integer value is the argument plus 232 if the argument is negative; otherwise, it is equal to the argument. This value is converted to a string of ASCII digits in hexadecimal (base 16) with no extra leading 0s. If the unsigned magnitude is zero, it is represented by a single zero character '0' ('&#92;u0030'); otherwise, the first character of the representation of the unsigned magnitude will not be the zero character. The following characters are used as hexadecimal digits: <blockquote>

 0123456789abcdef
 
</blockquote> These are the characters '&#92;u0030' through '&#92;u0039' and 'u' through '&#92;u0066'. If the uppercase letters are desired, the java.lang.String#toUpperCase() method may be called on the result: <blockquote>
 Long.toHexString(n).toUpperCase()
 
</blockquote>

Parameters:
i an integer.
Returns:
the string representation of the unsigned integer value represented by the argument in hexadecimal (base 16).
Since:
JDK1.0.2

static String java::lang::Integer::toOctalString ( jint  i  )  [static]

Creates a string representation of the integer argument as an unsigned integer in base 8.

The unsigned integer value is the argument plus 232 if the argument is negative; otherwise, it is equal to the argument. This value is converted to a string of ASCII digits in octal (base 8) with no extra leading 0s.

If the unsigned magnitude is zero, it is represented by a single zero character '0' ('&#92;u0030'); otherwise, the first character of the representation of the unsigned magnitude will not be the zero character. The octal digits are: <blockquote>

 01234567
 
</blockquote> These are the characters '&#92;u0030' through '&#92;u0037'.

Parameters:
i an integer
Returns:
the string representation of the unsigned integer value represented by the argument in octal (base 8).
Since:
JDK1.0.2

static String java::lang::Integer::toBinaryString ( jint  i  )  [static]

Creates a string representation of the integer argument as an unsigned integer in base 2.

The unsigned integer value is the argument plus 232if the argument is negative; otherwise it is equal to the argument. This value is converted to a string of ASCII digits in binary (base 2) with no extra leading 0s.

If the unsigned magnitude is zero, it is represented by a single zero character '0' ('&#92;u0030'); otherwise, the first character of the representation of the unsigned magnitude will not be the zero character. The characters '0' ('&#92;u0030') and '1' ('&#92;u0031') are used as binary digits.

Parameters:
i an integer.
Returns:
the string representation of the unsigned integer value represented by the argument in binary (base 2).
Since:
JDK1.0.2

static jint java::lang::Integer::parseInt ( const String s,
jint  radix = 10 
) [static]

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 java.lang.Character#digit(char, int) returns a nonnegative value), except that the first character may be an ASCII minus sign '-' ('&#92;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:

Examples: <blockquote>

 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
 
</blockquote>

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.
Exceptions:
NumberFormatException if the string does not contain a parsable integer.

static const Integer java::lang::Integer::valueOf ( const String s,
jint  radix = 10 
) [static]

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(java.lang.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: <blockquote>

 new Integer(Integer.parseInt(s, radix))  
 
</blockquote>

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.
Exceptions:
NumberFormatException if the String cannot be parsed as an int.

java::lang::Integer::operator jint & (  ) 

virtual jbyte java::lang::Integer::byteValue (  )  const [virtual]

Returns the value of this Integer as a byte.

Since:
JDK1.1

Reimplemented from java::lang::Number.

virtual jshort java::lang::Integer::shortValue (  )  const [virtual]

Returns the value of this Integer as a short.

Since:
JDK1.1

Reimplemented from java::lang::Number.

virtual jint java::lang::Integer::intValue (  )  const [virtual]

Returns the value of this Integer as an int.

Returns:
the int value represented by this object.

Implements java::lang::Number.

virtual jlong java::lang::Integer::longValue (  )  const [virtual]

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.

Implements java::lang::Number.

virtual jfloat java::lang::Integer::floatValue (  )  const [virtual]

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.

Implements java::lang::Number.

virtual jdouble java::lang::Integer::doubleValue (  )  const [virtual]

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.

Implements java::lang::Number.

virtual jboolean java::lang::Integer::equals ( const Object src  )  const [virtual]

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.

Parameters:
obj the object to compare with.
Returns:
true if the objects are the same; false otherwise.

Reimplemented from java::lang::Object.

virtual jint java::lang::Integer::hashCode (  )  const [virtual]

Returns a hashcode for this Integer.

Returns:
a hash code value for this object, equal to the primitive int value represented by this Integer object.

Reimplemented from java::lang::Object.

virtual jint java::lang::Integer::compareTo ( const Object src  )  const [virtual]

Compares this Integer to another Object.

If the Object is a Integer, this function behaves like compareTo(Integer). Otherwise, it throws a ClassCastException (as Integers are comparable only to other Integers).

Parameters:
o the Object to be compared.
Returns:
the value 0 if the argument is a Integer numerically equal to this Integer; a value less than 0 if the argument is a Integer numerically greater than this Integer; and a value greater than 0 if the argument is a Integer numerically less than this Integer.
Exceptions:
<code>ClassCastException</code> if the argument is not an Integer.
Since:
1.2

Reimplemented from java::lang::Comparable.

virtual String java::lang::Integer::toString (  )  const [virtual]

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 java.lang.Integer#toString(int) method.

Returns:
a string representation of the value of this object in base 10.

Reimplemented from java::lang::Object.


Member Data Documentation

const jint java::lang::Integer::MIN_VALUE [static]

The smallest value of type int.

The constant value of this field is -2147483648.

const jint java::lang::Integer::MAX_VALUE [static]

The largest value of type int.

The constant value of this field is 2147483647.


The documentation for this class was generated from the following file:
Generated on Fri May 16 11:56:37 2008 for CrossPlatformJavaLikeC++API by  doxygen 1.5.3