java – Converting hex to character code

Question:

I have a variable of type String , which contains the following value: "0xF9" .
How do I get the output character whose code is the hex value in this line?

Answer:

Option using Integer.decode method:

String str = "0xF9";
int code = Integer.decode(str);
char c = (char)code;

And the output to the screen in one line within the framework, relatively speaking, code golf:

System.out.println((char)(int)Integer.decode("0xF9"));
Scroll to Top