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


Stuff I use to make videos

Windows notebook – http://amzn.to/2zcXPyF

Apple MacBook Pro – http://amzn.to/2BTJBZ7

Desktop - http://amzn.to/2zct252

Microphone – http://amzn.to/2zcYbW1

notebook mouse – http://amzn.to/2BVs4Q3

Screen Recording Software – Camtasia