Skip to main content

Java : Convert String to int

We can use Integer.parseInt() and Integer.valueOf() to convert String to int.

Using Integer.parseInt()

Convert to integer primitive.

Using Integer.valueOf()

Convert to integer Object.

How to handle invalid number?

If String contains an invalid number. It will be thrown the NumberFormatException. It can be thrown or handled it.

 

 


Related Post

720total visits,3visits today

RSS
Follow by Email
Facebook
Facebook
Google+
http://mydevgeek.com/java-convert-string-int
Twitter