Alec Alec - 4 months ago 17
Java Question

How to get an integer at a specified position in a string of integers?

If I have a string like

String myString = "12345"
and I want to return the value at index [0]. How do I do this? I've tried for example
int foo = myString.charAt(0)
and get a weird value like 49?


Use Character.getNumericValue():

String myString = "12345";
int foo = Character.getNumericValue(myString.charAt(0));