and why should that be so? charAt gives the character value at the index indicated.
'3' does not yield 3 though.
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
In other words, read the API docs for Integer and its parse methods, and see if there is something there that can help you.
And find out what the difference between a char and an int is, as you can use a char as an int (as you've done here), but its value won't be what you seem to be expecting (find an ASCII character code table).
masijade
Industrious Poster
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
You just cast it. In Java a char is actually just like an int, it only depends on how you use it.
// Declaration of char c, initialized with the character 'a'.
char c = 'a';
// For int value of the character, cast to int: (int).
int i = (int) c;
// Do some work.
i++;
// Get the character back from the int by casting to char: (char).
c = (char) i;
// Now you see why 'b' comes after 'a' in the ascii table.
System.out.println(c);
Black Box
Black Box
Junior Poster in Training
62 posts since Nov 2007
Reputation Points: 60
Solved Threads: 7