About 1,370,000 results
Open links in new tab
  1. java - How to convert Integer to int? - Stack Overflow

    Aug 26, 2010 · For Java 1.4 and before, use Integer.intValue() to convert from Integer to int. BUT as you wrote, an Integer can be null, so it's wise to check that before trying to convert to int (or risk getting a NullPointerException ).

  2. How to Convert Integer to Int in Java - Delft Stack

    Feb 12, 2024 · In Java, we can convert an Integer object to a primitive int type using auto-unboxing. It is a feature introduced in Java 5 that allows the automatic conversion of an Integer object to its corresponding primitive int type.

  3. Type Conversion in Java with Examples - GeeksforGeeks

    Mar 24, 2025 · Use i mplicit conversion when assigning a value of a smaller data type to a larger data type (e.g., int to long). Use explicit conversion when assigning a value of a larger data type to a smaller data type (e.g., double to int) or when converting between incompatible types.

  4. Autoboxing and Unboxing (The Java™ Tutorials > Learning the Java ...

    Autoboxing is the automatic conversion that the Java compiler makes between the primitive types and their corresponding object wrapper classes. For example, converting an int to an Integer , a double to a Double , and so on.

  5. Java Type Casting - W3Schools

    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 …

  6. Convert Integer to Int in Java

    Aug 31, 2022 · We have three methods to convert java integer to int. Convert Integer to int Using assignment operator; Convert Integer to int Using intValue() method; Java Integer to int Using parseInt() method; Safe Conversion of Integer to Int in Java; Now we will discuss these method with example . Method 1 : Convert Integer to int Using assignment operator

  7. java - How to cast an Object to an int - Stack Overflow

    Jan 27, 2018 · If your object is a String, then you can use the Integer.valueOf() method to convert it into a simple int : int i = Integer.valueOf((String) object); It can throw a NumberFormatException if your object isn't really a String with an integer as content.

  8. Java Program to convert primitive types to objects and vice versa

    Dec 11, 2024 · In this article, you will learn how to convert primitive data types to their corresponding object forms and vice versa in Java. Through a set of practical examples, explore the automatic and manual conversions enabled by …

  9. Demystifying Integer to int Conversion in Java – TheLinuxCode

    Oct 30, 2023 · The most straightforward way to convert an Integer to int is by using the assignment operator =. For example: Integer num = 10; int primNum = num; // Assignment converts Integer -> int. Here, assigning the Integer object to an int variable causes num to be implicitly converted to an int.

  10. Autoboxing and Unboxing In Java

    Jun 26, 2023 · With autoboxing, the Java compiler automatically converts primitive types, such as int or boolean, into their respective wrapper classes, such as Integer or Boolean, when necessary. For example, when assigning an int value to an Integer object or passing an int as a parameter to a method that expects an Integer, autoboxing automatically ...

  11. Some results have been removed
Refresh