Home> Java> javaTutorial> body text

What is the concept of java escape characters and how to use them

WBOY
Release: 2023-05-11 18:55:13
forward
1237 people have browsed it

1. Concept

There are some characters in java that have special functions. If you want to express the character itself without expressing special effects, you can use escape characters at this time. .

2. Use

escape characters starting with \

\t Tab character: One tab character position represents 8 spaces

If the previous content satisfies an integer multiple of the tab position, re-open a tab position with 8 spaces

If the previous content is not satisfied, not a whole tab position

\n Line break

\b Cursor backspace

\r Cursor returns to the beginning of the line

3, Example

/* java中的转义字符 */ public static CharTest02{ public static void main(String[] args){ char c1 = 't'; System.out.println(c1); //根据已学内容,以下代码应该报错: //经过测试,以下代码可以通过编译,所以一下代码“\t” //实际上是一个字符,不属于字符串 //两个字符合在一起表示一个字符,其中\t边上“制表符tab” char c2 = '\t'; System.out.println("abc\tdef"); System.out.println("HelloWorld"); System.out.print("HelloWorld"); //"\"的出现会将紧挨着后面的字符进行转义 } }
Copy after login

The above is the detailed content of What is the concept of java escape characters and how to use them. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!