Java | Character class

05 min read

Character class:

  • Only one constructor — Character(char ch)

Character cc = new Character('x`);

  • To obtain the char value contained in a Character object,

char charValue( ) — returns a character

(eg) System.out.println(cc.charValue( )); --->  x

All methods of Character class specified below are static methods.

  1. static boolean isDigit(char ch)
  2. static boolean isLetter(char ch)
  3. static boolean isLetterOrDigit(char ch)
  4. static boolean isWhiteSpace(char ch)
  5. static boolean isLowerCase(char ch)
  6. static boolean isUpperCase(char ch)
  7. static boolean isTitleCase(char ch) --->  returns true if ch is a Unicode TitleCase character.
  8. static char toLowerCase(char ch) 
  9. static char toUpperCase(char ch)
  10. static char toTitleCase(char ch) ---> returns the title case equivalent of ch
  11. static char forDigit(int num, int radix) ---> returns the number/character equivalent of num, in the specified radix. (ie., decimal to specified radix(base))
  12. static int digit(char ch, int radix) ---> returns the integer value associated with the char specified by the radix (ie., specified radix to decimal)

Example:

Character.forDigit(15, 16);  ---> f (character equivalent of 15 in radix (base) 16 is f)

System.out.println(Character.forDigit(1, 10)); 1(number equivalent 1 in radix 10 is 1)

System.out.println(Character.digit('e',16)); ---> 14(the decimal equivalent of hexadecimalcharacter 'e' is 14)

System.out.printIn(Character.digit('1' 10)); ---> 1

Note:

Primitive Wrapper classes are immutable like String class. If you attempt to change the value of (say) an Integer object, the original object will not be modified; instead a new object will he created.

POST A NEW COMMENT
     
  • Input (stdin)

    Output (stdout)


    Input (stdin)

    Your Output (stdout)

    Expected Output

    Compiler Message

    Input (stdin)

    2    3

    Your Output (stdout)

    5

    Expected Output

    5

    Compiler Message

    5

    Error