Characters in Java

Characters in Java


Posted in : Core Java Posted on : September 29, 2010 at 5:58 PM Comments : [ 0 ]

This section contains the detail about character in java and it's use.

Characters in Java

To store character data, generally, we use primitive data type char. Java uses Unicode to represent character. For example :

char ch = 'a';

// Unicode for uppercase Greek omega character
char uniChar = '\u039A'; 

// an array of chars
char[] charArray ={ 'a', 'b', 'c', 'd', 'e' }; 

Situations occurs when we have need of using objects. Character wrapper class provide us this facility for primitive data type char. You can create character objects using character constructor as follows :

Character ch = new Character('x');

In some situation, java compiler automatically create a Character object. For example , you have a method which need an object as argument and you passed an primitive char to it, it will automatically convert primitive type to object. This is called boxing .

Example :

// Here following primitive char 'a' is boxed into the Character object ch

Character ch = 'a';

// Here primitive 'x' is boxed for method test,return is unboxed to char 'c'

char c = test('x');
 

Given below the methods for Character class implementation :

      Methods                  Description         
isLetter() It checks whether the specified char value is a letter.
isDigit() It checks whether the specified char value is a digit.
isWhitespace() It checks whether the specified char value is white space.
isUpperCase() It checks whether the specified char value is uppercase.
isLowerCase() It checks whether the specified char value is lowercase.
toUpperCase() Returns the uppercase form of the specified char value.
toLowerCase() Returns the lowercase form of the specified char value.
toString() Returns a String object representing the specified character valuethat is, a one-character string.
Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics