Why can't I use \u000D and \u000A as CR and LF in Java?

Viewed 39412

Why can't I use \u000D and \u000A as CR and LF in Java? It's giving an error when I compile the code:

String x = "\u000A hello";//Error - Illegal escape character in string literal.
3 Answers

建议最好不要用 It's better not to use it 试一下下面的代码,你就明白了 Try the following code and you'll see

public static void main(String[] args) {
    String a = "Hello";
    // \u000d a="world";
    System.out.println(a);
    // \u000a a="hello world!";
    System.out.println(a);
}
Related