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.
public long longValue()
Parameters: This method do not take any parameters.
Return Value: This method will return the numeric value represented by this object after conversion to long type.
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.
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.
prog.java:9: error: integer number too large: 97387717187 Long lobject = new Long(97387717187); ^ 1 error
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- Number.longValue() method in java with examples
- BigDecimal longValue() Method in Java
- BigInteger longValue() Method in Java
- Byte longValue() method in Java with examples
- Short longValue() method in Java with Example
- LongAdder longValue() method in Java with Examples
- DoubleAdder longValue() method in Java with Examples
- LongAccumulator longValue() method in Java with Examples
- AtomicInteger longValue() method in Java with examples
- AtomicLong longValue() method in Java with examples
- DoubleAccumulator longValue() method in Java with Examples
- Double longValue() in Java with Examples
- Float longValue() in Java with Examples
- Java Math addExact(long x, long y) method
- Java Math subtractExact(long x, long y) method
- Java Guava | Longs.checkedSubtract(long a, long b) method with Examples
- Duration ofSeconds(long, long) method in Java with Examples
- Java Guava | LongMath.checkedAdd(long a, long b) method with Examples
- Java Guava | Longs.indexOf(long array, long target) method with Examples
- Java Guava | LongMath.divide(long, long, RoundingMode) method with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.