0% found this document useful (0 votes)
62 views2 pages

Example:: // Unicode For Uppercase Greek Omega Character

1. The Character class is a wrapper class for the primitive data type char. It allows chars to be used as objects. 2. Escape sequences are used to represent special characters like tabs, newlines, and quotes through the use of a backslash. Common escape sequences and their meanings are shown in a table. 3. The Character class has useful methods like isLetter(), isDigit(), toUpperCase(), and toLowerCase() for manipulating individual characters.

Uploaded by

wincaacbay19
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views2 pages

Example:: // Unicode For Uppercase Greek Omega Character

1. The Character class is a wrapper class for the primitive data type char. It allows chars to be used as objects. 2. Escape sequences are used to represent special characters like tabs, newlines, and quotes through the use of a backslash. Common escape sequences and their meanings are shown in a table. 3. The Character class has useful methods like isLetter(), isDigit(), toUpperCase(), and toLowerCase() for manipulating individual characters.

Uploaded by

wincaacbay19
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Example:

char ch = 'a';

// Unicode for uppercase Greek omega character


char uniChar = '\u039A';

// an array of chars
char[] charArray ={ 'a', 'b', 'c', 'd', 'e' };
However in development, we come across situations where we need to use objects instead of primitive data types. In
order to achieve this, Java provides wrapper class Character for primitive data type char.

The Character class 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');

The Java compiler will also create a Character object for you under some circumstances. For example, if you pass a
primitive char into a method that expects an object, the compiler automatically converts the char to a Character for
you. This feature is called autoboxing or unboxing, if the conversion goes the other way.

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');

Escape Sequences:
A character preceded by a backslash (\) is an escape sequence and has special meaning to the compiler.

The newline character (\n) has been used frequently in this tutorial in System.out.println() statements to advance to
the next line after the string is printed.

Following table shows the Java escape sequences:

Escape Sequence Description

\t Inserts a tab in the text at this point.

\b Inserts a backspace in the text at this point.

\n Inserts a newline in the text at this point.

\r Inserts a carriage return in the text at this point.

\f Inserts a form feed in the text at this point.

\' Inserts a single quote character in the text at this point.

\" Inserts a double quote character in the text at this point.

\\ Inserts a backslash character in the text at this point.

When an escape sequence is encountered in a print statement, the compiler interprets it accordingly.
Example:
If you want to put quotes within quotes you must use the escape sequence, \", on the interior quotes:

public class Test {

public static void main(String args[]) {


System.out.println("She said \"Hello!\" to me.");
}
}

This would produce the following result:

She said "Hello!" to me.

Character Methods:
Here is the list of the important instance methods that all the subclasses of the Character class implement:

SN Methods with Description

isLetter()
1
Determines whether the specified char value is a letter.

isDigit()
2
Determines whether the specified char value is a digit.

isWhitespace()
3
Determines whether the specified char value is white space.

isUpperCase()
4
Determines whether the specified char value is uppercase.

isLowerCase()
5
Determines whether the specified char value is lowercase.

toUpperCase()
6
Returns the uppercase form of the specified char value.

toLowerCase()
7
Returns the lowercase form of the specified char value.

toString()
8
Returns a String object representing the specified character valuethat is, a one-character string.

For a complete list of methods, please refer to the java.lang.Character API specification.

You might also like