The intValue()
method of Integer class returns the value of this Integer object as int. You can use this method for Integer to int conversion.
Syntax of intValue() method
public int intValue()
intValue() Parameters
NA
intValue() Return Value
- Returns the value represented by Integer object as int primitive data type.
Example 1
A value contained by Integer object is converted into an int primitive data type using intValue()
method.
class JavaExample { public static void main(String args[]) { Integer iObj = new Integer(33); //This method is called using Integer object //and returns an equivalent int value int iNum = iObj.intValue(); System.out.println("Integer to int: "+iNum); } }
Output:
Example 2
The given string contains an integer value. This string is converted into an Integer object using Integer.valueOf() method and then the obtained Integer object is converted into an int using intValue()
method.
class JavaExample { public static void main(String args[]) { String s = "123456"; Integer iObj = Integer.valueOf(s); System.out.println("Integer object value: "+iObj); int iNum = iObj.intValue(); System.out.println("int value: "+iNum); } }
Output: