Alec Alec - 1 year ago 66
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?

Answer Source

Use Character.getNumericValue():

String myString = "12345";
int foo = Character.getNumericValue(myString.charAt(0)); 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download