BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

Java Integer longValue() Method

Last Updated: October 27, 2022 by Chaitanya Singh | Filed Under: java

The longValue() method of Integer class, returns the value represented by this Integer object as long. Since the size of long is greater than the size of int data type, It is also called widening primitive conversion.

Syntax of longValue() method

public long longValue()

longValue() Parameters

  • It does not have any parameter.

longValue() ReturnValue

  • Returns a long value. This value is numerically equivalent to the value contained in this Integer object.

Example 1

This example demonstrates the use of longValue() method. Here, we have an Integer object and we are converting the value of it into a long primitive data type.

class JavaExample {
  public static void main(String args[]) {
    Integer iObj = new Integer(400);
    long lNum = iObj.longValue(); //Integer to long
    System.out.println("Integer object value: "+iObj);
    System.out.println("long value: "+lNum);
  }
}

Output: