About 1,560,000 results
Open links in new tab
  1. How to Convert a String to an int in Java? - GeeksforGeeks

    Nov 25, 2024 · 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().

  2. How do I convert a String to an int in Java? - Stack Overflow

    You can convert a String to an int in Java using Integer.parseInt(). Here's a quick example: String value = "1234"; int number = Integer.parseInt(value); Make sure the string contains a valid integer, otherwise a NumberFormatException will be thrown. If you're unsure about the input, wrap it with a try-catch block to handle errors safely.

  3. Java String to Int – How to Convert a String to an Integer

    Nov 23, 2020 · In Java, we can use Integer.valueOf() and Integer.parseInt() to convert a string to an integer. 1. Use Integer.parseInt () to Convert a String to an Integer. This method returns the string as a primitive type int. If the string does not contain a valid integer then it will throw a NumberFormatException.

  4. Convert String to int or Integer in Java - Baeldung

    Dec 15, 2023 · Converting a String to an int or Integer is a very common operation in Java. In this article, we will show multiple ways of dealing with this issue. There are a few simple ways to tackle this basic conversion. 2. Integer.parseInt()

  5. Java Type Casting - W3Schools

    Type casting is when you assign a value of one primitive data type to another type. In Java, there are two types of casting: Widening Casting (automatically) - converting a smaller type to a larger type size byte-> short-> char-> int-> long-> float-> double; Narrowing Casting (manually) - converting a larger type to a smaller size type double ...

  6. Java Type Casting (With Examples) - Programiz

    In Widening Type Casting, Java automatically converts one data type to another data type. Example: Converting int to double class Main { public static void main(String[] args) { // create int type variable int num = 10; System.out.println("The integer value: " + num); // convert into double type double data = num; System.out.println("The double ...

  7. Convert String to int in Java (with Examples) - HowToDoInJava

    Jan 10, 2023 · learned to parse a string (decimal, octal and hexadecimal) to int or Integer types using Integer.parseInt(), valueOf() and decode() methods.

  8. Java String to int - Tpoint Tech

    We can convert String to an int in Java using Integer.parseInt () and Integer.valueOf () method. These methods return instance of the Integer class. In this section, we will discuss the ways to covert String to int in Java. It is generally used, if we have to perform mathematical operations on the string which contains a number.

  9. Java String to Int Conversion – Different Methods Explained

    Mar 22, 2025 · One of the simplest and most efficient ways to convert a string to an integer in Java is by using built-in parsing functions. These methods ensure that the conversion is handled efficiently and throw exceptions if the input is invalid.

  10. String to int in Java - GeeksforGeeks

    Nov 22, 2024 · 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() .

Refresh