How to Convert a String to an int in Java? Last Updated : 25 Nov, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report In Java, converting a String to an int is done using methods from the Integer class. The methods used for this conversion are Integer.parseInt() and Integer.valueOf(). Example: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. If the string contains any non-numeric characters, a NumberFormatException will be thrown. Java // Java Program to convert String to int public class StringToInt { public static void main(String[] args) { String s = "123"; // Convert string to int using parseInt int n = Integer.parseInt(s); System.out.println("The integer value is: " + n); } } OutputThe integer value is: 123 Comment More infoAdvertise with us Next Article 5 Ways to Convert Double to Integer in Java C code_r Follow Improve Article Tags : Java Java-Strings Java-String-Programs Practice Tags : JavaJava-Strings Similar Reads Convert String to Double in Java In this article, we will convert a String to a Double in Java. There are three methods for this conversion from String to Double, as mentioned below in the article.Methods for String-to-Double ConversionDifferent ways for converting a String to a Double are mentioned below:Using the parseDouble() me 3 min read String to int in Java Converting a String to an int in Java can be done using methods provided in the Integer class, such as Integer.parseInt() or Integer.valueOf() methods. Example:The most common method to convert a string to a primitive int is Integer.parseInt(). It throws a NumberFormatException if the string contain 2 min read Java Convert int to String - Different Ways of Conversion Converting an int to a String is an important type conversion. Many operations can be performed over a string, while we are limited when it comes to integers. We have a wide varied list of in-built methods in the String class that help us perform hassle-free operations. Suppose we are required to co 9 min read 5 Ways to Convert Double to Integer in Java Double is a primitive data type in Java that is used to represent double-precision floating point numbers. It uses the IEEE 754 standard for representing floating point numbers and has a default value of 0.0d. The double data type is the default data type for decimal numbers in Java and has a defaul 5 min read Convert a String to an Integer using Recursion Given a string str representing a string, the task is to convert the given string into an integer.Examples: Input: str = "1235" Output: 1235Explanation: "1235" is converted to the integer 1235 by extracting and combining its digits.Input: str = "0145" Output: 145 ApproachTo recursively converts a nu 3 min read Different ways for String to Integer Conversions in Java Given a String in Java, the task is to convert this String into Integer. Examples: Input: str = "1234" Output: 1234 Input: str = "456" Output: 456 Convert using Integer.parseInt(String) The Integer class has a static method that returns an integer object representing the specified String parameter. 2 min read Like