java character

java character

In Java, the Character class is a wrapper class for the char primitive type. It provides utility methods for working with char values, such as converting them to and from strings, testing their type (such as whether they are letters or digits), and converting them to upper- or lowercase.

Here are some examples of using the Character class:

  • To convert a char value to a String, you can use the toString method:
refer to:‮tual‬turi.com
char ch = 'A';
String str = Character.toString(ch);  // str is "A"
  • To test whether a char value is a letter, you can use the isLetter method:
char ch = 'A';
boolean isLetter = Character.isLetter(ch);  // isLetter is true
  • To test whether a char value is a digit, you can use the isDigit method:
char ch = '3';
boolean isDigit = Character.isDigit(ch);  // isDigit is true
  • To convert a char value to upper- or lowercase, you can use the toUpperCase or toLowerCase method:
char ch = 'a';
char upperCase = Character.toUpperCase(ch);  // upperCase is 'A'
char lowerCase = Character.toLowerCase(ch);  // lowerCase is 'a'

The Character class also provides other utility methods for working with char values, such as isWhitespace, isUpperCase, and isLowerCase. You can find more information about these methods in the Java documentation.

Created Time:2017-11-03 00:14:48  Author:lautturi