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.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Unicode escapes are pre-processed before the compiler is run. Therefore, if you put
\u000Ain a String literal like this:It will be compiled exactly as if you wrote:
Stick to
\r(carriage return;0x0D) and\n(line feed;0x0A)Bonus: You can always have fun with this, especially given the limitations on most syntax highlighters. Next time you’ve got a sec, try running this code: