APCS Java Subset

ap.java.lang
Class Integer

java.lang.Object
  |
  +--ap.java.lang.Integer
All Implemented Interfaces:
Comparable

public class Integer
extends java.lang.Object
implements Comparable

The class Integer is an immutable wrapper class for the primitive type int, allowing primitive values in some contexts to be treated as objects.

The four methods below are those specified in the APCS Java subset for the wrapper class Integer. An object whose type is Integer encapsulates a single int value. The methods in the APCS Java subset are applicable to Integer objects. Two static methods not in the subset are often useful in practice. These methods, parseInt and toString are shown in use in the following code.

     String s = Integer.toString(1024);  // s is "1024"
     int i = Integer.parseInt("12345")   // i is 12345
 


Constructor Summary
Integer(int value)
          Constructs an immutable Integer wrapping value.
 
Method Summary
 int compareTo(Object other)
          Compares two Integer objects and returns a value consistent with the contract of Comparable.compareTo and with the value returned by Integer.equals.
 boolean equals(Object other)
          Determines if this Integer object is equal to another.
 int intValue()
          Returns the value represented by this object.
 String toString()
          Returns a representation of this object as a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Integer

public Integer(int value)
Constructs an immutable Integer wrapping value.

Parameters:
value - is the value wrapped by this object
Method Detail

intValue

public int intValue()
Returns the value represented by this object.

Returns:
the primitive int value represented by this object

equals

public boolean equals(Object other)
Determines if this Integer object is equal to another. This method returns true if and only if this.intValue() == int.doubleValue().

Parameters:
other - is the other Integer object to which this one is compared
Returns:
true if this object is equal to other.

toString

public String toString()
Returns a representation of this object as a string.

Overrides:
toString in class java.lang.Object
Returns:
a string form of this Integer object.

compareTo

public int compareTo(Object other)
Compares two Integer objects and returns a value consistent with the contract of Comparable.compareTo and with the value returned by Integer.equals.

Specified by:
compareTo in interface Comparable
Parameters:
other - is the Integer object to which this one is compared
Returns:
the value 0 if this object is equal to other, a value less than 0 if this object is less than other, and a value greater than 0 if this object is greater than other

unofficial documentation for the APCS Java Subset