\x Escape in Java?

Viewed 40760

I was wondering if there is a similar hex (\x) escape in Java like there is in C++. For example:

char helloworld[] = "\x48\x45\x4C\x4C\x4F\x20\x57\x47\x52\x4C\x44";
printf("%s", helloworld);

There is no hex (\x) escape in Java from what it appears so far. Is there an alternative that is just as easy to use without having to concat a bunch of hex numbers together?

2 Answers

Note that Unicode escapes are parsed quite early. It can come as a surprise when

  String s = "text\u000d\u000a";

causes a compiler error because you should have used "text\015\012" or "text\r\n"

Related