Computer >> Computer tutorials >  >> Programming >> Java

Character Class in Java


The Character class wraps a value of the primitive type char in an object. An object of class Character contains a single field whose type is char.

Following are some of the methods of the Character class −

Modifier and TypeMethod and Description
static intcharCount(int codePoint)
Determines the number of char values needed to represent the specified character
charcharValue()
Returns the value of this Character object.
static int.codePointAt(char[] a, int index)
Returns the code point at the given index of the char array.
static intcodePointAt(char[] a, int index, int limit)
Returns the code point at the given index of the char array, where only array elements with index less than limit can be used.
static intcodePointAt(CharSequence seq, int index)
Returns the code point at the given index of the CharSequence.
static intcodePointBefore(char[] a, int index)
Returns the code point preceding the given index of the char array.

Example

Let us see an example −

import java.lang.*;
public class Demo {
   public static void main(String[] args){
      System.out.println(Character.isLetter('0'));
      System.out.println(Character.isLetter('h'));
      System.out.println(Character.isLetter('K'));
   }
}

Output

This will produce the following output −

false
true
true

Let us now see another example −

Example

import java.lang.*;
public class Demo {
   public static void main(String[] args){
      System.out.println(Character.isLetter('0'));
      System.out.println(Character.isLetter('h'));
      System.out.println(Character.isLetter('K'));
      System.out.println(Character.toString('0'));
      System.out.println(Character.toString('H'));
   }
}

Output

This will produce the following output −

false
true
true
0
H