Convert String to int using Java




In Java, we can use Integer.parseInt() method to convert a String to int.

Example 1. Using Integer.parseInt()

public static int parseInt(String s, int radix) throws NumberFormatException Parses the string argument as a signed decimal integer.
The Example below can be used to convert a String “1000” to an primitive integer.

Integer.parseInt() throws NumberFormatException

Other examples of using Integer.parseInt()

Example 2. Java convert string to int Using Integer.valueOf()

Integer.valueOf() Returns an Integer object holding the value extracted from the specified String when parsed with the radix given by the second argument.

Sources:

 





Partner Sites

VideoToGifs.com

EasyOnlineConverter.com

SqliteTutorials.com