I have a string like, "12345" and want to convert it to the integer array, {1,2,3,4,5}.
I want one method to convert a character to an integer, '1' -> 1. And another method to create the array.
This is what I have so far:
public static int charToInt(char character) {
int newInt;
newInt = (int) character;
return newInt;
}
public static int[] convertStringToIntArray(String keyString) {
int keyLength = keyString.length();
int element;
int[] intArray = new int[keyLength];
for (element = 0; element < keyLength; element++) {
intArray[element] = charToInt(keyString.charAt(element));
}
// return
return intArray;
}
I think the problem is in the charToInt method. I think it is converting the char to its ascii value. But I am not sure if the other method is right either.
Any help would be greatly appreciated.