The java.lang.Integer.intValue() is an inbuilt method in java that returns the value of this integer as an int.
Syntax :
public int intValue()
Parameters: The method does not accept any parameters.
Return Value : The method returns the numeric value which is represented by the object after conversion to the integer type.
Below programs illustrate the java.lang.Integer.intValue() method:
Program 1: For a positive integer.
// Java praogram to illustrate the use of // java.lang.Integer.intValue() method import java.lang.*; public class Geeks { public static void main(String[] args) { Integer intobject = new Integer(68); // Returns the value of this Integer as an int int i = intobject.intValue(); System.out.println("The integer Value of i = " + i); } } |
The integer Value of i = 68
Program 2: For a negative number.
// Java praogram to illustrate the use of // java.lang.Integer.intValue() method import java.lang.*; public class Geeks { public static void main(String[] args) { Integer intobject = new Integer(-76); // Returns the value of this Integer as an int int i = intobject.intValue(); System.out.println("The integer Value of i = " + i); } } |
The integer Value of i = -76
Program 3: For a decimal value and string.
Note:It returns an error message when a decimal value and string is given.
// Java praogram to illustrate the use of // java.lang.Integer.intValue() method import java.lang.*; public class Geeks { 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 intobject = new Integer("52"); int i = intobject.intValue(); System.out.println("The integer Value of i = " + i); } } |
Output:
prog.java:9: error: no suitable constructor found for Integer(double)
Integer intobject = new Integer(98.22);
^
constructor Integer.Integer(int) is not applicable
(argument mismatch; possible lossy conversion from double to int)
constructor Integer.Integer(String) is not applicable
(argument mismatch; double cannot be converted to String)
prog.java:14: error: variable intobject is already defined in method main(String[])
Integer intobject = new Integer("52");
^
prog.java:17: error: variable i is already defined in method main(String[])
int i = intobject.intValue();
^
3 errors
Recommended Posts:
- BigDecimal intValue() Method in Java
- BigInteger intValue() Method in Java
- Byte intValue() method in Java with examples
- Number.intValue() method in java with examples
- Float intValue() method in Java with examples
- Double intValue() method in Java with examples
- Integer sum() Method in Java
- Integer lowestOneBit() Method in Java
- Integer highestOneBit() Method in Java
- Java Integer compareUnsigned() method
- Java Integer bitCount() method
- Integer doubleValue() Method in Java
- Integer reverse() Method In Java
- Java Integer compare() method
- Java Integer byteValue() method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



