Online Java Compiler By
JavaTpoint.com
public class JavaCharacterCompareToExample1 { public static void main(String[] args) { Character firstVal = new Character('g'); Character secondVal = new Character('G'); // compare the first character to the second character. intcompare1= firstVal.compareTo(secondVal); if (compare1 == 0) { System.out.println("The first value 'g' and the second value 'G' are equal."); } else if (compare1>0) { System.out.println("The first value 'g' is greater than the second value 'G'."); } else { System.out.println("The first value 'g' is less than the second value'G'."); } } }
Output