intValue() of Integer class that is present inside java.lang package is an inbuilt method in java that returns the value of this integer as an int which is inherited from Number Class. The package view is as follows:
--> java.lang Package
--> Integer Class
--> intValue() Method
Syntax:
public int intValue()
Return Type: A numeric value that is represented by the object after conversion to the integer type.
Note: This method is applicable from java version 1.2 and onwards.
Now we will be covering different numbers such as positive, negative, decimal, and even strings.
- For a positive integer
- For a negative number
- For a decimal value and string
Case 1: For a positive integer
Example:
Java
import java.lang.*;
public class GFG {
public static void main(String[] args)
{
Integer intobject = new Integer( 68 );
int i = intobject.intValue();
System.out.println( "The integer Value of i = " + i);
}
}
|
Output: The integer Value of i = 68
Case 2: For a negative number
Example:
Java
import java.lang.*;
public class GFG {
public static void main(String[] args)
{
Integer intobject = new Integer(- 76 );
int i = intobject.intValue();
System.out.println( "The integer Value of i = " + i);
}
}
|
Output: The integer Value of i = -76
Case 3: For a decimal value and string.
Example:
Java
import java.lang.*;
class GFG {
public static void main(String[] args)
{
Integer intobject = new Integer( 98.22 );
int i = intobject.intValue();
System.out.println( "The integer Value of i = " + i);
Integer ab = new Integer( "52" );
int a = ab.intValue();
System.out.println( "The integer Value of ab = "
+ a);
}
}
|
Output:

Note: It returns an error message when a decimal value is given. For a string this works fine.