java.lang.Integer longValue()

Description :

This java tutorial shows how to use the longValue() method of Integer class under java.lang package. This method returns the long equivalent of this Integer object. The method longValue() were inherited from Number class

Method Syntax :

public long longValue()

Parameter Input :

DataType Parameter Description

Method Returns :

The longValue() method simply returns the numeric value represented by this object after conversion to type long.

Compatibility Version :

Requires Java 1.0 and up

Exception :


Java Code Example :

This java example source code demonstrates the use of longValue() method of Integer class. Basically we ask for an int input from the console, and then we use the scanner to get the value. After that we assign the value to an Integer wrapper class and then get the long equivalent using the longValue() method of Integer class.


import java.util.Scanner;

import static java.lang.System.*;

 * This example source code demonstrates the use of 
 * longValue() method of Integer class.

public class IntegerLongValue {

	public static void main(String[] args) {
		// Ask user input
		System.out.print("Enter Desired Value:");
		// declare the scanner object
		Scanner scan = new Scanner(;
		// use scanner to get the value from user console
		int intValue = scan.nextInt();
		// close the scanner object
		Integer myValue = new Integer(intValue);
		long value = myValue.longValue();
		out.println("long Value is " + value);



Sample Output :

Running the toLongValue() method example source code of Integer class will give you the following output

Enter Desired Value:1024
long Value is 1024

Exception Scenario :


Similar Method :

  • N/A

Suggested Reading List :

References :