Java Character check char value

Introduction

Character is a simple wrapper around a char.


public class Main {
  public static void main(String args[]) {
    char a[] = {'a', 'b', '5', '?', 'A', ' '};

    for(int i=0; i<a.length; i++) {
      if(Character.isDigit(a[i]))
        System.out.println(a[i] + " is a digit.");
      if(Character.isLetter(a[i]))
        System.out.println(a[i] + " is a letter.");
      if(Character.isWhitespace(a[i]))
        System.out.println(a[i] + " is whitespace.");
      if(Character.isUpperCase(a[i]))
        System.out.println(a[i] + " is uppercase.");
      if(Character.isLowerCase(a[i]))
        System.out.println(a[i] + " is lowercase.");
    }//from   w w w .  j a  v a 2 s .c  om
  }
}
public class Main 
{
   public static void main(String[] args)
   {// w  w  w.j a  v  a2  s . co m
      
      char c = 'C'; // get input character

      // display character info
      System.out.printf("is defined: %b\n", Character.isDefined(c));
      System.out.printf("is digit: %b\n", Character.isDigit(c));
      System.out.printf("is first character in a Java identifier: %b\n",
         Character.isJavaIdentifierStart(c));
      System.out.printf("is part of a Java identifier: %b\n",
         Character.isJavaIdentifierPart(c));
      System.out.printf("is letter: %b\n", Character.isLetter(c));
      System.out.printf(
         "is letter or digit: %b\n", Character.isLetterOrDigit(c));
      System.out.printf(
         "is lower case: %b\n", Character.isLowerCase(c));
      System.out.printf(
         "is upper case: %b\n", Character.isUpperCase(c));
      System.out.printf(
         "to upper case: %s\n", Character.toUpperCase(c));
      System.out.printf(
         "to lower case: %s\n", Character.toLowerCase(c));
   } 
}



PreviousNext

Related