Arrays and Strings · Introduction to Java Programming

Character Class

Watch lectures

Character Class

1. Why Wrap a char? (beginner)

char is primitive (fast, no methods). Character adds helpers: is digit/letter? upper/lower? Plus ArrayList<Character> storage and null option.

System.out.println(Character.isDigit('5'));     // true
System.out.println(Character.isLetter('A'));    // true
System.out.println(Character.isLetterOrDigit('!')); // false
System.out.println(Character.isUpperCase('A')); // true
System.out.println(Character.toUpperCase('a')); // A
System.out.println(Character.toLowerCase('Z')); // z
System.out.println(Character.isWhitespace(' ')); // true (space/tab/newline!)
System.out.println(Character.digit('A', 16));   // 10 (hex A → 10!)

4. Traps

  • Character (object) vs char (primitive): ArrayList<char> ERROR, ArrayList<Character> ok!
  • == on Characters: cache trap like Integer (use .equals() / unbox!).
  • char + int = int: 'A'+1 → 66 (not 'B'! cast: (char)('A'+1) → 'B').

5. Exam Points

  • Helper table + validator program — 5 marks, frequent.
  • char vs Character, +1 trap — 3 marks, frequent.
Student FinanceWeb Platform

Pocketly — Personal Finance for Students

Keep your hostel and college expenses under control. Track accounts, log spending in seconds, and stay within your monthly budget.

← All Introduction to Java Programming modules