๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ integer-valueof-vs-integer-parseint-with-examples
Integer.valueOf() vs Integer.parseInt() with Examples - GeeksforGeeks
July 11, 2025 - It takes a valid string as a parameter and parses it into primitive data type int. It only accepts String as a parameter and on passing values of any other data type, it produces an error due to incompatible types.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ how-to-convert-string-to-int-in-java
String to int in Java - GeeksforGeeks
The most common method to convert a string to a primitive int is Integer.parseInt(). It throws a NumberFormatException if the string contains non-numeric characters. ... // Java Program to demonstrate // String to int conversion using parseInt() ...
Published ย  July 23, 2025
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ java โ€บ number_parseint.htm
Java - parseInt() Method
Java Vs. C++ ... This method is used to get the primitive data type of a certain String. parseXxx() is a static method and can have one argument or two. ... parseInt(int i) โˆ’ This returns an integer, given a string representation of decimal, ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ string-to-integer-in-java-parseint
String to Integer in Java - parseInt() - GeeksforGeeks
February 4, 2021 - To complete your preparation from ... int parseInt(String s) throws NumberFormatException - This function parses the string argument as a signed decimal integer....
๐ŸŒ
GeeksforGeeks
origin.geeksforgeeks.org โ€บ java โ€บ integer-valueof-vs-integer-parseint-with-examples
Integer.valueOf() vs Integer.parseInt() with Examples - GeeksforGeeks
September 5, 2023 - The method generally used to convert String to Integer in Java is parseInt(). This method belongs to Integer class in java.lang package. It takes a valid string as a parameter and parses it into primitive data type int.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ how-to-convert-a-string-to-an-int-in-java
How to Convert a String to an int in Java? - GeeksforGeeks
July 12, 2025 - The Integer.parseInt() is a commonly used method to convert a string to an integer in Java. This method converts a numeric string to an int by interpreting each character as a digit.
๐ŸŒ
Oracle
docs.oracle.com โ€บ javase โ€บ 7 โ€บ docs โ€บ api โ€บ java โ€บ lang โ€บ Integer.html
Integer (Java Platform SE 7 )
+ DecimalNumeral, HexDigits, and ... of The Javaโ„ข Language Specification, except that underscores are not accepted between digits. The sequence of characters following an optional sign and/or radix specifier ("0x", "0X", "#", or leading zero) is parsed as by the Integer.parseInt method with ...
๐ŸŒ
Javatpoint
javatpoint.com โ€บ java-integer-parseint-method
Java Integer parseInt() Method - Javatpoint
Java Integer parseInt() Method - The Java parseInt() method is a method of Integer class that belong to java.lang package. The parseInt() method in Java is crucial for converting string representations of numbers into actual integer values. This capability is fundamental in various programming ...
๐ŸŒ
Study.com
study.com โ€บ courses โ€บ business courses โ€บ business 104: information systems and computer applications
How to Convert String to Int in Java - ParseInt Method - Lesson | Study.com
January 9, 2023 - Java allows for many types of data type conversion. This lesson describes how to convert a String variable into an integer value using the ParseInt method in Java.
Find elsewhere
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ java-program-to-convert-char-to-int
Java Program to Convert Char to Int - GeeksforGeeks
// Java program to convert Char to Int // Using valueOf() method of String Class class Geeks { // Main driver method public static void main(String[] args) { // Declaring and initializing a character char ch = '3'; // Printing the character value System.out.println("char value: " + ch); // Converting the character to it's integer value // using valueOf() method int a = Integer.parseInt(String.valueOf(ch)); // Printing the integral value // corresponding to its character value System.out.println("int value: " + a); } } Output ยท
Published ย  July 12, 2025
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ parseint() in java
parseInt() in Java - Scaler Topics
May 8, 2024 - It is used in Java for converting a string value to an integer by using the method parseInt().
๐ŸŒ
Quora
quora.com โ€บ How-does-Integer-parseInt-work-in-Java
How does Integer.parseInt() work in Java? - Quora
Answer (1 of 4): Usually this is done like this: * init result with 0 * for each character in string do thisresult = result * 10get the digit from the character ('0' is 48 ASCII (or 0x30), so just subtract that from the character ASCII code to get the digit)add the digit to the result * retur...
Top answer
1 of 8
47

Usually this is done like this:

  • init result with 0
  • for each character in string do this
    • result = result * 10
    • get the digit from the character ('0' is 48 ASCII (or 0x30), so just subtract that from the character ASCII code to get the digit)
    • add the digit to the result
  • return result

Edit: This works for any base if you replace 10 with the correct base and adjust the obtaining of the digit from the corresponding character (should work as is for bases lower than 10, but would need a little adjusting for higher bases - like hexadecimal - since letters are separated from numbers by 7 characters).

Edit 2: Char to digit value conversion: characters '0' to '9' have ASCII values 48 to 57 (0x30 to 0x39 in hexa), so in order to convert a character to its digit value a simple subtraction is needed. Usually it's done like this (where ord is the function that gives the ASCII code of the character):

digit = ord(char) - ord('0')

For higher number bases the letters are used as 'digits' (A-F in hexa), but letters start from 65 (0x41 hexa) which means there's a gap that we have to account for:

digit = ord(char) - ord('0')
if digit > 9 then digit -= 7

Example: 'B' is 66, so ord('B') - ord('0') = 18. Since 18 is larger than 9 we subtract 7 and the end result will be 11 - the value of the 'digit' B.

One more thing to note here - this works only for uppercase letters, so the number must be first converted to uppercase.

2 of 8
28

The source code of the Java API is freely available. Here's the parseInt() method. It's rather long because it has to handle a lot of exceptional and corner cases.

public static int parseInt(String s, int radix) throws NumberFormatException {
    if (s == null) {
        throw new NumberFormatException("null");
    }

    if (radix < Character.MIN_RADIX) {
        throw new NumberFormatException("radix " + radix +
            " less than Character.MIN_RADIX");
    }

    if (radix > Character.MAX_RADIX) {
        throw new NumberFormatException("radix " + radix +
            " greater than Character.MAX_RADIX");
    }

    int result = 0;
    boolean negative = false;
    int i = 0, max = s.length();
    int limit;
    int multmin;
    int digit;

    if (max > 0) {
        if (s.charAt(0) == '-') {
            negative = true;
            limit = Integer.MIN_VALUE;
            i++;
        } else {
            limit = -Integer.MAX_VALUE;
        }
        multmin = limit / radix;
        if (i < max) {
            digit = Character.digit(s.charAt(i++), radix);
            if (digit < 0) {
                throw NumberFormatException.forInputString(s);
            } else {
                result = -digit;
            }
        }
        while (i < max) {
            // Accumulating negatively avoids surprises near MAX_VALUE
            digit = Character.digit(s.charAt(i++), radix);
            if (digit < 0) {
                throw NumberFormatException.forInputString(s);
            }
            if (result < multmin) {
                throw NumberFormatException.forInputString(s);
            }
            result *= radix;
            if (result < limit + digit) {
                throw NumberFormatException.forInputString(s);
            }
            result -= digit;
        }
    } else {
        throw NumberFormatException.forInputString(s);
    }
    if (negative) {
        if (i > 1) {
            return result;
        } else { /* Only got "-" */
            throw NumberFormatException.forInputString(s);
        }
    } else {
        return -result;
    }
}
๐ŸŒ
Global Tech Council
globaltechcouncil.org โ€บ home โ€บ what is parseint in java?
What is parseInt in Java? - Global Tech Council
July 5, 2025 - In Java, parseInt is a method used to convert a string into a whole number (an integer).
๐ŸŒ
H2K Infosys
h2kinfosys.com โ€บ blog โ€บ introduction to parseint in java
Introduction to ParseInt in Java
September 24, 2024 - The parseInt function of the Integer class receives the string โ€œ123โ€ as an input in this example, and it transforms the string into the integer value 123 and stores it in the number variable.
๐ŸŒ
Java Code Geeks
examples.javacodegeeks.com โ€บ home โ€บ web development โ€บ javascript
JavaScript parseInt() - Java Code Geeks
November 9, 2022 - The javascript parseInt function converts its first argument to a string, parses that string, then returns an integer or NaN. If not NaN, the return value will be the integer that is the first argument taken as a number in the specified radix.
๐ŸŒ
BeginnersBook
beginnersbook.com โ€บ 2022 โ€บ 10 โ€บ java-integer-parseintmethod
Java Integer parseInt()Method
Here, we have two char sequences and we are parsing the part of the these sequences using parseInt() method of Integer class. public class JavaExample { public static void main(String[] args) { String s = "Hello1001Bye"; String s2 = "LEAF"; //taking 1001 part from string s int i = Integer.parseInt(s, 5, 9, 10); //taking EA from the string s2 and using 16 to parse it as hex int i2 = Integer.parseInt(s2, 1, 3, 16); System.out.println("int value: "+i); //Hex "EA" is equal to 234 in decimal System.out.println("int value: "+i2); } }
๐ŸŒ
vteams
vteams.com โ€บ blog โ€บ use-of-parseint-java-programming
Learn the Basics & Ins-And-Outs of PARSEint Java Programming
February 23, 2024 - There are also some things you should keep in mind when using the PARSEInt while coding. Basically, PARSE int Java programming is a method that converts a string to an integer. So, when you are using the method you have to use two arguments.