The intValue() method of Java Integer class returns an int value for this Integer.
Syntax
public int intValue()
Parameters
NA
Specified by
This method is specified by intValue in class Number
Return Value
This method returns the numeric value of this object after conversion to type int.
Example 1
1 2 3 4 5 6 7 8 9 10 |
public class JavaIntegerIntValueExample1 { public static void main(String[] args) { Integer a=456; //returns primitive int value for Integer a int val=a.intValue(); System.out.println("int value "+a+" : "+val); } } |
Output
1 2 3 |
int value 456 : 456 |
Example 2
1 2 3 4 5 6 7 8 9 10 |
public class JavaIntegerIntValueExample2 { public static void main(String[] args) { int a=456; //Here, a is the primitive type object it cannot be used to call Integer class methods int val=a.intValue(); System.out.println("int value "+a+" : "+val); } } |
Output
1 2 3 |
Error:(7, 18) java: int cannot be dereferenced |