Compare Character

 
class MainClass {
  public static void main(String[] args) {
    Character c1 = new Character('6');
    Character c2 = new Character('7');

    char c3 = c1.charValue();
    char c4 = c2.charValue();

    if (c3 < c4)
      System.out.println(c3 + " is less than " + c4);

    if (c1.compareTo(c2) < 0)
      System.out.println(c1 + " is less than " + c4);
  }
}

public class CharacterDemo {
  public static void main(String args[]) {
    Character a = new Character('a');
    Character a2 = new Character('a');
    Character b = new Character('b');

    int difference = a.compareTo(b);

    if (difference == 0) {
      System.out.println("a is equal to b.");
    } else if (difference < 0) {
      System.out.println("a is less than b.");
    } else if (difference > 0) {
      System.out.println("a is greater than b.");
    }

    System.out.println("a is " + ((a.equals(a2)) ? "equal" : "not equal")
        + " to a2.");

    System.out.println("The character " + a.toString() + " is "
        + (Character.isUpperCase(a.charValue()) ? "upper" : "lower")
        + "case.");
  }
}
  
Home 
  Java Book 
    Runnable examples  

Data Type Char:
  1. Create Character from char value
  2. Compare Character
  3. Character.isLowerCase, isUpperCase check the letter case
  4. Character.isLetter checks if a char is a letter
  5. Character.isDigit checks the if a char is a digit
  6. Character.isWhitespace checks if a letter is a space
  7. Character.UnicodeBlock checks a Character's Unicode Block
  8. Convert char to integer ASCII code
  9. Convert ASCII code int value to String
  10. Convert char to unicode
  11. Convert char array to string
  12. Get next char value
  13. Store unicode in a char variable
  14. Check char type
  15. Max and Min values of char