Java Integer.longValue() – Examples

In this tutorial, we will learn about Java Integer.longValue() method, and learn how to use this method to get the value of this integer object as long value, with the help of examples.

longValue()

Integer.longValue() returns the value of this Integer as a long after a widening primitive conversion.

Syntax

The syntax of longValue() method is

</>
Copy
Integer.longValue()

Returns

The method returns value of type long.

Example – longValue()

In this example, we will take an Integer object and get an equivalent long value of this integer object.

Java Program

</>
Copy
public class Example {
	public static void main(String[] args){
		Integer integer = 20;
		long result = integer.longValue();
		System.out.println("Result of longValue() = " + result);
	}
}

Output

Result of longValue() = 20

Conclusion

In this Java Tutorial, we have learnt the syntax of Java Integer.longValue() method, and also how to use this method with the help of Java example programs.