Cases of parseInt() Method

Let’s take a random code snippet further understand the illustrations better.

Case 1: parseInt(“20”, 16)

returns 32 , (2)*16^1 + (0)*16^0 = 32

Case 2: parseInt(“2147483648”, 10)

throws a NumberFormatException

Case 3: parseInt(“99”, 8)

throws a NumberFormatException
Reason: 9 is not an accepted digit of octal number system

Case 4: parseInt(“geeks”, 28)

throws a NumberFormatException

Case 5: parseInt(“geeks”, 29)

returns 11670324, Reason: Number system with base 29 can have digits 0-9 followed by characters a,b,c… upto s

Case 6: parseInt(“w3wiki”, 29)

throws a NumberFormatException as the Reason: result is not an integer.

String to int in Java

In Java, while operating upon strings, there are times when we need to convert a number represented as a string into an integer type. We usually do this because we can operate with a wide flexible set of operations over strings. The method generally used to convert String to Integer in Java is parseInt() of the String class.

In this article, we will see how to convert a String to int in Java.

Similar Reads

Program to Convert Java String to int

Let us take an example straight away to get used to the working parseInt() method :...

parseInt() Method in Java

...

Cases of parseInt() Method

There are two variants of this method:...

Number Format Exceptions of parseInt() Method

Let’s take a random code snippet further understand the illustrations better....

Another Approach for Converting a String to Integer

Exceptions caused by parseInt() Method mentioned below:...