Java String to Int

This article shows how to convert a Java string to int .

To convert a Java String that represents an integer value, to the int type, one can use the utility methods of the Integer class.

Convert Java string to int using Integer.parseInt()

Output

 

Alternatively, you can also use the Integer.valueOf() to achieve the same.

Convert Java string to int using Integer.valueOf()

Output

 

However, if the string does not represent a integer value then any attempt to convert such a string to int would throw java.lang.NumberFormatException.

Converting a non-integer string

Output

 


 

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

Previous article

Tracking thread pool in Java

Next article

Split a String