🌐
Tutorialspoint
tutorialspoint.com › home › java › java integer parsing
Java Integer Parsing
September 1, 2008 - 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, ...
🌐
W3Schools
w3schools.com › jsref › jsref_parseint.asp
W3Schools.com
parseInt("10", 10); parseInt("010"); parseInt("10", 8); parseInt("0x10"); parseInt("10", 16); Try it Yourself » ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com ...
🌐
W3Schools Blog
w3schools.blog › home › string to int in java
String to int in java - W3schools
March 18, 2018 - The Integer.parseInt() method is used to convert string to int in java. It returns a primitive int value.
🌐
W3Schools
w3schools.in › java › examples › convert-string-int
Java Program to Convert String to Int - W3Schools
This Java program converts String to Integer. Java Integer class has parseInt() static method, which is used convert string to int.
🌐
Javaprogramto
javaprogramto.com › 2017 › 10 › string-to-int.html
How to convert a String to an int in Java? JavaProgramTo.com
public class ParseIntExample { // Java - W3schools public static void main(String[] args) { String s = "12345"; int i = Integer.parseInt(s); System.out.println("i value : "+i); } } Output: i value : 12345 Note: If we pass alphabetic in string to the parseInt method then it will throw NumberFormatException.
🌐
GitHub
github.com › java-w3schools › Tutorials › blob › master › CoreJava › src › main › java › com › java › w3schools › blog › string › StringToIntparseIntExample.java
Tutorials/CoreJava/src/main/java/com/java/w3schools/blog/string/StringToIntparseIntExample.java at master · java-w3schools/Tutorials
package com.java.w3schools.blog.string; · /** * Java - String to Int Conversion Examples · * · * @author Venkateshn · * */ public class StringToIntparseIntExample { · public static void main(String[] args) { · // Way 1 · String string = "12345"; int intValue = Integer.parseInt(string); System.out.println("converted int Value : " + intValue); ·
Author   java-w3schools
🌐
W3Schools Blog
w3schools.blog › home › java string to int
Java String to int - W3schools
March 18, 2018 - Java convert string to int example program code in eclipse : The Integer.parseInt() method is used to convert string to int in java.
🌐
W3Schools
w3schools.am › jsref › jsref_parseint.html
JavaScript parseInt() Function
The parseInt() function parses a string and returns an integer. The radix parameter is used to specify which numeral system to be used, for example, a radix of 16 (hexadecimal) indicates that the number in the string should be parsed from a hexadecimal number to a decimal number.
🌐
GeeksforGeeks
geeksforgeeks.org › java › integer-valueof-vs-integer-parseint-with-examples
Integer.valueOf() vs Integer.parseInt() with Examples - GeeksforGeeks
July 11, 2025 - Integer.parseInt(): While operating upon strings, there are times when we need to convert a number represented as a string into an integer type. The method generally used to convert String to Integer in Java is parseInt(). This method belongs ...
Find elsewhere
🌐
W3Schools
w3schools.com › jsref › tryit.asp
W3Schools online HTML editor
The W3Schools online code editor allows you to edit code and view the result in your browser
🌐
Scaler
scaler.com › home › topics › parseint() in java
parseInt() in Java - Scaler Topics
May 8, 2024 - Learn about parseInt in Java. Scaler Topics explains the syntax, working of each method along with parameters, return value, and examples.
🌐
W3Resource
w3resource.com › javascript › functions › parselnt-function.php
JavaScript parseInt function - w3resource
The parseInt is used to get a numeric value from a string. parseInt is a top-level function and is not associated with any object.
🌐
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); } }
🌐
Java Tutorial HQ
javatutorialhq.com › java tutorial › java.lang › integer › parseint() method example
Java Integer parseInt() method example
September 30, 2019 - In my years of java programming, I have encountered so many instances that I have to convert from String object to another data type. The Integer.parseInt method is a very convenient Java API to transform a user input in String format into a more robust object type which in this case the ...
🌐
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.
🌐
W3Schools
www-db.deis.unibo.it › courses › TW › DOCS › w3schools › jsref › jsref_parseint.asp.html
JavaScript parseInt() Function
The parseInt() function parses a string and returns an integer. The radix parameter is used to specify which numeral system to be used, for example, a radix of 16 (hexadecimal) indicates that the number in the string should be parsed from a hexadecimal number to a decimal number.
🌐
Global Tech Council
globaltechcouncil.org › home › what is parseint in java?
What is parseInt in Java? - Global Tech Council
August 22, 2025 - Understanding how to use parseInt in Java function effectively can save you a lot of trouble in managing input data and performing mathematical operations in your programs.
🌐
LabEx
labex.io › tutorials › java-java-integer-parseint-method-117728
Java parseInt(String, int) | Integer Parsing Tutorial | LabEx
In this lab, we have learned how to use the Java parseInt(String s, int radix) method to parse a string value into a signed decimal integer object relative to a specified radix value.
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):

Copydigit = 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:

Copydigit = 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.

Copypublic 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;
    }
}