Long longValue() Method in Java Last Updated : 03 Jan, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report The java.lang.Long.longValue() is an inbuilt method of the Long class in Java which returns the value of this Long object as a long after the conversion.Syntax: public long longValue() Parameters: This method does not take any parameters.Return Value: This method will return the numeric value represented by this object after conversion to long type.Examples: Input: 5366623 Output: (Long) 5366623 Input: -6723887 Output: (Long) -6723887 Explanation: When the number is passed in this object it will convert that to long and gives the value like, Long lobject = new Long(5366623) It will return 5366623 as long. Below programs illustrate the working of java.lang.Long.longValue() method. Program 1: For a positive number. java // Java program to illustrate the // java.lang.Long.longValue() method import java.lang.*; public class Geek { public static void main(String[] args) { Long lobject = new Long(77387187); // It will return the value of this Long as a long long nl = lobject.longValue(); System.out.println("The Value of nl as long is = " + nl); Long lobject2 = new Long(-6723887); // It will return the value of this Long as a long long nl2 = lobject2.longValue(); System.out.println("The Value of nl2 as long is = " + nl2); } } Output: The Value of nl as long is = 77387187 The Value of nl2 as long is = -6723887 Program 2: For a very large no. // It will produce compile time error. java // Java program to illustrate the // java.lang.Long.longValue() method import java.lang.*; public class Geek { public static void main(String[] args) { Long lobject = new Long(97387717187); // Very large number will produce compile errors long nl = lobject.longValue(); System.out.println("The Value of nl as long is = " + nl); } } Output: prog.java:9: error: integer number too large: 97387717187 Long lobject = new Long(97387717187); ^ 1 error Reference: https://docs.oracle.com/javase/7/docs/api/java/lang/Long.html#longValue() Comment More infoAdvertise with us Next Article Long longValue() Method in Java A ankita_chowrasia Follow Improve Article Tags : Java Java-lang package Java-Functions java-Long Practice Tags : Java Similar Reads LongAdder longValue() method in Java with Examples LongAdder class in Java creates a new adder with an initial sum of zero. The Java.LongAdder.longValue() is an inbuilt method in java that returns the sum(). This method is equivalent to the sum() method. When the object of the class is created its initial value is zero. Syntax: public long longValue 2 min read BigInteger longValue() Method in Java The java.math.BigInteger.longValue() converts this BigInteger to a long value. If the value return by this function is too big to fit into long value, then it will return only the low-order 64 bits. There is chance that this conversion can lose information about the overall magnitude of the BigInteg 2 min read BigDecimal longValue() Method in Java The java.math.BigDecimal.longValue() is an in-built function which converts this BigDecimal to a long value. This function discards any fractional part of this BigDecimal. The function returns only the lower-order 64 bits when the result of the conversion is too big to be represented as a long value 2 min read LongAccumulator longValue() method in Java with Examples The java.LongAccumulator.longValue() is an inbuilt method in java that is equivalent to the get() method that is this method just returns the current value. Syntax: public long longValue() Parameters: This method does not accepts any parameter. Return Value: The method returns the current value. Bel 1 min read BigDecimal longValueExact() Method in Java The java.math.BigDecimal.longValueExact() is an in-built function which converts this BigDecimal to a long value as well as checks for lost information. This function throws Arithmetic Exception if there is any fractional part of this BigDecimal or if the result of the conversion is too big to be re 3 min read Like