Java Character Class

Source: Internet
Author: User
Tags uppercase letter

Java Character Class

The Character class is used to manipulate individual characters.

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

Instance
char 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:

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 ch = ' A '//  raw character ' X ' is boxed with the test method / / Returns the value of the unboxing to ' C '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:
// the original character ' a ' is boxed into the Character object ch Character ch = ' A '//  raw character ' X ' is boxed with the test method / / Returns the value of the unboxing to ' C 'char c = Test (' x ');

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

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

List of Notes
      1. \ r: Return to the leftmost side of the current line.

        \ n: NewLine moves down one line and does not move around.

        Linux \ n means: Carriage return + line change;

        Windows \ r \ n means: Carriage return + line break.

        The \ r in Mac means: Carriage return + line break.

        History:

        The origins and differences between the two concepts of carriage return "(carriage return) and" line feed ". Before the computer appeared, there was a thing called a telex typewriter (the concept of TTY under the teletype Model 33,linux/unix), which can be played 10 characters per second. But it has a problem, that is, when the line is finished, it will take 0.2 seconds to hit two characters. If there are new characters coming in this 0.2 seconds, then this character will be lost. So, the developers think of a way to solve this problem, is to add two after each line to end the character. One is called "return", which tells the typewriter to position the printhead at the left border, and the other is called "newline", which tells the typewriter to move the paper down one line. This is the origin of "line break" and "carriage return", from their English name can also be seen in one or two.

Java Character Class

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.