java.lang.Long intValue()
Description
The Long.intValue() java method returns the value of this Long as an int after a narrowing primitive conversion. Please be careful in using this method because of the conversion will undergo narrowing if the original value is much larger than the max value allowable for primitive int.
Method Syntax
public int intValue()
Method Argument
Data Type | Parameter | Description |
---|
Method Returns
The intValue() method of Long class returns the numeric value represented by this object after conversion to type int.
Compatibility
Requires Java 1.0 and up
Java Long intValue() Example
Below is a simple java example on the usage of intValue() method of Long class.
package com.javatutorialhq.java.examples; /* * This example source code demonstrates the use of * intValue() method of Long class */ public class LongIntValueExample { public static void main(String[] args) { // Declare a new Long variable Long value = 123l; // get the intValue() method result int result = value.intValue(); // print the result System.out.println("Result:" + result); /* * Be careful on using this method * Desired result might differ * because of the narrowing concept * of java language */ } }
Sample Output
Below is the sample output when you run the above example.