Java Integer compareTo() methodThe 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:
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 |
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