Java Integer intValue() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Integer

Definition

In Java, boxed.intValue() returns the plain int stored inside an Integer object. This is called unboxing. Java normally does it for you, so you rarely need to call the method by hand.

The method comes from the Number class, the parent of Integer, Long, Double, and the other wrapper types. That is why intValue() also works on a Double, where it cuts off the decimal part.

An instance method of java.lang.Integer: call it on an Integer object. Integer lives in java.lang, so no import is needed.

Syntax

Call it on an Integer (or any Number). It takes no arguments.

Java
Integer boxed = 250;
int a = boxed.intValue();     // 250
int b = boxed;                // 250 (automatic unboxing)
Number n = 3.99;
int c = n.intValue();         // 3 (the decimal part is dropped)
CallWhat it does
boxed.intValue()The int inside an Integer.
int n = boxed;Automatic unboxing; calls intValue() for you.
number.intValue()Converts any Number to int, dropping any decimal part.
Integer.valueOf(n)The opposite direction: boxes an int.

Calling intValue() (or letting Java unbox) on a null reference throws NullPointerException.

Library declarations
Java
// java.lang.Integer
public int intValue()

// Inherited contract from java.lang.Number
public abstract int intValue()

Parameters

ParameterDescription
NoneintValue() takes no parameters.

Return Value

Return ValueDescription
intThe primitive value held by the Integer. For other Number types it is a converted value, so a long or double may be truncated.

Compare with Similar Methods

Related conversions:

MethodHow it differs
longValue()Unwraps to a wider long, so nothing is lost.
doubleValue()Unwraps to a double, useful for division with decimals.
valueOf(i)The reverse: wraps an int in an Integer.
parseInt(s)Gets an int from text rather than from an object.

Java Examples

Example 1 — Unwrap an Integer into an int

Unwrap an Integer explicitly, and compare with automatic unboxing in arithmetic.

Java
public class IntegerIntValueDemo {
    public static void main(String[] args) {
        Integer boxed = 250;

        int manual = boxed.intValue();
        int automatic = boxed;
        System.out.println("manual:    " + manual);
        System.out.println("automatic: " + automatic);

        System.out.println("boxed + 5: " + (boxed + 5));
        System.out.println("equal:     " + (manual == automatic));
    }
}

How It Works

  1. An object holds the number. boxed is an Integer object that stores 250.
  2. Two ways to unwrap. intValue() and plain assignment to an int both produce 250.
  3. Arithmetic unboxes too. The + operator unwraps the object by itself, so boxed + 5 is 255.
  4. Same result. The two int variables hold the same number, so the comparison is true.

Example 2 — Convert Other Number Types with intValue

Call intValue() on an array of mixed Number objects and see how decimals are handled.

Java
public class IntegerIntValueNumber {
    public static void main(String[] args) {
        Number[] values = {Integer.valueOf(42), 3.99, -3.99, 7L, 2.5f, 3000000000L};

        for (Number value : values) {
            System.out.println(value + " -> " + value.intValue());
        }
    }
}

How It Works

  1. One method, many types. The array holds Integer, Double, Long, and Float objects, and every one of them has intValue() from Number.
  2. Decimals are cut off. 3.99 becomes 3 and 2.5 becomes 2. Nothing is rounded.
  3. Negative decimals go toward zero. -3.99 becomes -3, not -4.
  4. A long that is too big. 3000000000 does not fit in an int, so only its low 32 bits remain and the result is -1294967296.

Example 3 — Avoid the NullPointerException from Unboxing

Store counts in a map and see what happens when you unbox a missing entry.

Java
import java.util.HashMap;
import java.util.Map;

public class IntegerIntValueNull {
    public static void main(String[] args) {
        Map<String, Integer> stock = new HashMap<>();
        stock.put("pens", 12);

        int pens = stock.get("pens");
        System.out.println("pens: " + pens);

        Integer pencils = stock.get("pencils");
        System.out.println("pencils is null: " + (pencils == null));

        try {
            int count = stock.get("pencils");
            System.out.println(count);
        } catch (NullPointerException e) {
            System.out.println("unboxing null -> NullPointerException");
        }

        int safe = stock.containsKey("pencils") ? stock.get("pencils") : 0;
        System.out.println("safe count: " + safe);
    }
}

How It Works

  1. A present key unboxes fine. stock.get("pens") returns an Integer holding 12, and the assignment turns it into an int.
  2. A missing key gives null. Map.get returns null for "pencils", which is fine while it stays an Integer.
  3. Unboxing null fails. Assigning that null to an int calls intValue() on nothing, which throws NullPointerException.
  4. The safe pattern. Check containsKey first, or test for null, and use a default such as 0.

Frequently Asked Questions

It returns the primitive int stored inside an Integer object. It is the explicit form of automatic unboxing.
Usually not. Java unboxes automatically when you assign an Integer to an int or use it in arithmetic.
The Integer variable is null, so there is no object to unwrap. This often happens with Map.get for a missing key. Check for null first.
No. Number.intValue() cuts the decimal part off, so 3.99 becomes 3 and -3.99 becomes -3. Use Math.round if you want rounding.
Long.intValue() keeps only the low 32 bits, so the result can be completely different. Use Math.toIntExact to get an exception instead.

Next: longValue()

Widen an Integer to a primitive long.

longValue() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful