Reputation: 7636
I want to transform an int
to a String
such that:
0 -> "a"
1 -> "b"
2 -> "c"
and so on...
How can I do this?
Upvotes: 0
Views: 220
Reputation: 93664
You can convert from the character literal:
int input = 0;
String output = new Character((char) (input + 'a')).toString();
Upvotes: 3
Reputation: 9314
An alternate method, for some java library flavor:
int value;
String output = Integer.toString(value + 10, 36);
which uses a radix of 36 to locate the right letter.
Upvotes: 0
Reputation: 218828
Your question is a little unclear, but it sounds like you want to be able to convert integers 0-25 to their corresponding alphabetical characters. If that's the case, your best bet logically is probably to use an enum. Though I may not be fully seeing the purpose of what you're trying to do (which is likely).
You could also write a utility method which just has a big switch statement to convert them.
Upvotes: 0