- 1
Why we can't convert string consists of alphabet to integer ?
5 Respuestas
0
I don't know if I get your question correct but there is a way we can convert all the alphabets in the string to their ASCII value.
e.g.
String str = "ABC";
int a = str.charAt(0);
// a will print 65
0
but why we can't change it directly through string method only
0
The simple reason for this is that letters can not be converted into numbers. There is only a way to get the letter's ASCII code by treating them as chars, Like @Turtle did it in his answer.
0
what is benefits of this convert??
0
Because String is an object and not a char so you cannot type cast it and the Integer.parseInt method does not support letters.