Convert specified character in a String to an int

I have a String composed of a series of numbers and need to get an int value of the number, i.e., convert "7" to 7.  Figured out how to do it, am wondering if there is a simpler way.

String theInput = "5678";
int intTemp = Integer.parseInt(String.valueOf(theInput.charAt(2)));

gives me intTemp = 7;

Thanks.
LVL 9
dancebertAsked:
Who is Participating?
 
sudhakar_koundinyaConnect With a Mentor Commented:

Also
int intTemp = Integer.parseInt(""+theInput.charAt(2));
0
 
sudhakar_koundinyaCommented:
int intTemp = Integer.parseInt(String.valueOf(""+theInput.charAt(2)));
0
 
sudhakar_koundinyaCommented:
Also
int intTemp = Integer.parseInt(theInput.charAt(2));
0
 
sudhakar_koundinyaCommented:

Also
int intTemp =(int)theInput.charAt(2)-(int)'0';
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.