Java character compareTo() methodThe compareTo(character another character) method of character class is used to compare two objects numerically. SyntaxParameterThe above method requires only one parameter: The character that need to be compared. ReturnThe compare(char x, char y) method of character class returns : The value 0 if the given Character is equal to the argument Character. A value less than 0 if the given Character is numerically less than the Character argument A value greater than the given Character is numerically greater than the Character argument. Example 1Test it NowOutput: The first value 'g' is greater than the second value 'G'. Example 2Test it NowOutput: The first value 't' is greater than the second value 'G'. Example 3Test it NowOutput: The first value is greater than the second value The first and third value are equal
Next TopicJava Character
|