Java Character Class

Source: Internet
Author: User
Tags uppercase letter

The Character class is used to manipulate individual characters.

The Character class wraps the value of a base type char in an object

InstanceChar Ch=‘A‘;//Unicode character representation Char Unichar=‘\u039A‘;//Character array char[] chararray ={ "a b ' , c ' d" ' e ' }

However, in the actual development process, we often encounter situations where objects need to be used rather than built-in data types. To solve this problem, the Java language provides the wrapper class character class for the built-in data type char.

The character class provides a series of methods to manipulate characters. You can create a character class object using character's construction method, for example:

Character ch = new Character('a');

In some cases, the Java compiler automatically creates a character object.

For example, when a parameter of type char is passed to a method that requires a character type parameter, the compiler automatically converts the char type parameter to the character object. This feature is called boxing, which in turn is called unpacking.

Instance//The original character ' a ' is boxed into the Character object ch character Span class= "Hl-identifier" >ch = ' a// original character ' X ' boxed // Return the value of the unboxing to ' C ' < Span class= "Hl-code" > char c = test ( x ' Escape sequences

A character preceded by a backslash (\) represents an escape character, which has a special meaning for the compiler.

The following list shows the escape sequences for Java:

Escape Sequences Description
\ t Insert a TAB key in the text
\b Insert a back key in the text
\ n The line wraps in the text.
\ r Insert a carriage return at this point in the text
\f Insert a page break at this point in the text
\‘ Insert single quotation marks at the same place in the text
\" Insert double quotation marks at this point in the text
\\ Inserts a backslash in the text
Instance

When a print statement encounters an escape sequence, the compiler can interpret it correctly.

The following instance escapes the double quotes and outputs:

Test.java File Code:Public Class Test { Public Static void main ( String args[ ]) { system. Out. Println ( " access \ " Rookie Tutorial! \ "" ) } } /span>

The results of the above example compilation run as follows:

Visit "Rookie Tutorial!"
Character method

Here are the methods of the character class:

Serial Number Method and Description
1 Isletter ()
Whether it is a letter
2 IsDigit ()
Whether it is a numeric character
3 Iswhitespace ()
Whether it is a space
4 Isuppercase ()
Whether it is an uppercase letter
5 Islowercase ()
Whether it is a lowercase letter
6 toUpperCase ()
Specify the uppercase form of the letter
7 toLowerCase ()
Specifies the lowercase form of the letter
8 ToString ()
Returns the string form of a character with a string length of only 1

Java Character Class

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.