What does “\1” represent in this Java string?

谁说我不能喝 提交于 2019-11-30 16:24:49

问题


System.out.println("\1");

I thought it did not compile because of the non-recognized escape sequence.

What does "\1" exactly represent?


回答1:


It's an octal escape sequence, as listed in section 3.10.6 of the JLS. So for example:

String x = "\16";

is equivalent to:

String x = "\u000E";

(As Octal 16 = Hex E.)

So \1 us U+0001, the "start of heading" character.

Octal escape sequences are very rarely used in Java in my experience, and I'd personally avoid them where possible. When I want to specify a character using a numeric escape sequence, I always use \uxxxx.




回答2:


In java It is following value

\u0001


来源:https://stackoverflow.com/questions/17616286/what-does-1-represent-in-this-java-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!