Compare two integer values
int compareTo(Integer anotherInteger)
- Compares two Integer objects numerically.
boolean equals(Object obj)
- Compares this object to the specified object.
Returns from compareTo(Integer anotherInteger)
Value | Description |
---|---|
0 | if this Integer is equal to the argument Integer; |
less than 0 | if this Integer is less than the argument Integer; |
greater than 0 | if this Integer is greater than the argument Integer. |
public class Main {
public static void main(String[] args) {
Integer integer1 = new Integer("1");
Integer integer2 = new Integer("2");
System.out.println(integer1.compareTo(integer2));
}
}
The output:
-1
Home
Java Book
Essential Classes
Java Book
Essential Classes
Integer:
- Integer class
- Max, min value of an integer type variable
- Create Integer using its constructors
- Return an integer value as byte, double, float, int, long and short
- Compare two integer values
- Decode a string and return an integer value
- Convert string to integer
- Convert integer to string
- Reverse and rotate the integer in binary format
- Bit oriented operation
- Return system property as integer
- Get the leading and trailing zeros
- Get the sign of an Integer
- Convert integer to binary, hexdecimal and octal format