|
APCS Java Subset | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectap.java.lang.Integer
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 |
public Integer(int value)
Integer
wrapping value.
value
- is the value wrapped by this objectMethod Detail |
public int intValue()
int
value represented by
this objectpublic boolean equals(Object other)
Integer
object is equal to
another. This method returns true if and only
if this.intValue() == int.doubleValue()
.
other
- is the other Integer
object to which
this one is compared
other
.public String toString()
Integer
object.public int compareTo(Object other)
Integer
objects and returns
a value consistent with the contract of
Comparable.compareTo
and with the value
returned by Integer.equals
.
compareTo
in interface Comparable
other
- is the Integer
object to which this
one is compared
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 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |