Java Integer compareTo() method25 Mar 2025 | 2 min read The compareTo() method is a method of Integer class under java.lang package. This method compares two integer objects numerically. It returns the result of the value 0 if Integer is equal to the argument Integer, a value less than 0 if Integer is less than the argument Integer and a value greater than 0 if Integer is greater than the argument Integer. This method is specified by Comparable<Integer>Interface. Note: This method cannot be compared two different types of argument, so both the argument and the number should be the same type.SyntaxFollowing is the declaration of compare() method: Parameter:
Returns:This method will returns the following values: Exceptions:NA Compatibility Version:Java 1.2 and above Example 1Output: -1 0 1 Example 2Output: x is greater than y Example 3Output: 1 0 -1 Example 4Output: Enter the integer value to be campare with another Integer: 200 -1 0 1 Next TopicJava-integer-compareunsigned-method |
Java Method The toString() method of Java Integer class is used to get a String object representing the value of the Number Object. There are three different types of Java toString() method which can be differentiated depending on its parameter. These are: Java Method Java Integer...
3 min read
Java Method The equals() method is a method of Integer class under java.lang package. This method compares the value of the parameter to the value of the current Integer object. It returns Boolean (True or False) which corresponds to the equality of this Integer and...
3 min read
Java Method The hashCode() method is a Java Integer class method which returns the hash code for the given inputs. There are two different types of Java hashCode() method which can be differentiated depending on its parameter. These are: Java Method Java Integer hashCode(int value) Method hashCode()...
3 min read
This method is used to get an unsigned String object representing the value of the Number Object. There is two different types of Java toUnsignedString() method which can be differentiated depending on its parameter. These are: Java Integer toUnsignedString(int i) Method Java Integer toUnsignedString(int i, int radix) Method 1....
3 min read
Java method The byteValue() is a method of byte class under java.lang package. It converts the given number into a primitive byte type and returns the value of integer object as byte. Also, it override the byteValue() method of Number class. Syntax Following is the declaration of...
2 min read
Java Method The divideUnsigned() is a method of Java Integer class which returns the unsigned quotient of dividing the first argument by the second argument where each argument and the result is interpreted as an unsigned value. Syntax: Following is the declaration of divideUnsigned() method: public static int...
2 min read
Java Method The rotateRight() method of Java Integer class returns the value obtained by rotating the two's complement binary representation of the specified int value right by the specified number of bits. (Bits shifted out of the right hand, or low-order). Bit shifting is a bitwise...
3 min read
Java Method The lowestOneBit() method is a method of Integer class under java.lang package. This method returns int value with at most a single one-bit, in the position of the lowest-order ("rightmost") one-bit in the specified int value. If the specified value has no one-bits...
2 min read
Java Method The reverse() method of Java Integer class numerically returns the value obtained by reversing the order of the bits in the 2's complement binary representation of the specified integer value. Syntax: Following is the declaration of reverse() method: public static int reverse(int i) Parameter: DataType Parameter Description Required/Optional int i Integer value whose bits...
2 min read
Java method The bitCount() is a method of Integer class under java.lang package. It returns the number of one-bits in the two's complement binary representation of the specified int value. This function is sometimes referred to as the population count. Syntax Following is the declaration of bitCount()...
2 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India