Olian04 Olian04 - 6 months ago 14
Java Question

Char to int and back again

I want to find an integer representation of a character, then later on find a character representation of an int.

My current solution is this, but it doesn't work:

String s = "A"
Integer b = Character.getNumericValue(s.toCharArray()[0]); // 10
char c = Character.toChars(b)[0]; // (blank)


How should i do this?

Answer
int b = s.charAt(0); // 65
char c = (char) b  // 'A'