What is the character wrapper class and its methods in Java?

Java Programming Java8Object Oriented Programming

The Character class of the java.lang package wraps a value of the primitive datatype char. It offers a number of useful class (i.e., static) methods for manipulating characters. You can create a Character object with the Character constructor.

Character ch = new Character('a');

Following are the notable methods of the Character class.

1

isLetter()

Determines whether the specified char value is a letter.

2

isDigit()

Determines whether the specified char value is a digit.

3

isWhitespace()

Determines whether the specified char value is white space.

4

isUpperCase()

Determines whether the specified char value is uppercase.

5

isLowerCase()

Determines whether the specified char value is lowercase.

6

toUpperCase()

Returns the uppercase form of the specified char value.

7

toLowerCase()

Returns the lowercase form of the specified char value.

8

toString()

Returns a String object representing the specified character value that is, a one-character string.

Example

Live Demo

public class CharacterClassExample {
   public static void main(String[] args) {
      char ch1, ch2;
      ch1 = '9';
      ch2 = 'V';
      
      boolean b1, b2;
      b1 = Character.isDigit(ch1);
      b2 = Character.isDigit(ch2);
      
      String str1 = ch1 + " is a digit is " + b1;
      String str2 = ch2 + " is a digit is " + b2;
      System.out.println( str1 );
      System.out.println( str2 );
   }
}

Output

9 is a digit is true
V is a digit is false
raja
Published on 22-Apr-2018 17:37:18
Advertisements