java.lang.Long.longValue()是Java中Long类的内置方法,该方法在转换很长时间后返回此Long对象的值。
用法:
public long longValue()
参数:此方法不带任何参数。
返回值:转换为long类型后,此方法将返回此对象表示的数值。
例子:
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.
以下程序说明了java.lang.Long.longValue()方法的用法。
示例1:为正数。
// Java praogram 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);
}
}
输出:
The Value of nl as long is = 77387187 The Value of nl2 as long is = -6723887
示例2:对于非常大的数字。
//将产生编译时错误。
// Java praogram 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);
}
}
输出:
prog.java:9: error: integer number too large: 97387717187 Long lobject = new Long(97387717187); ^ 1 error
参考: https://docs.oracle.com/javase/7/docs/api/java/lang/Long.html#longValue()
相关用法
- Java Short longValue()用法及代码示例
- Java BigInteger longValue()用法及代码示例
- Java BigDecimal longValue()用法及代码示例
- Java LongAdder longValue()用法及代码示例
- Java DoubleAdder longValue()用法及代码示例
- Java LongAccumulator longValue()用法及代码示例
- Java AtomicInteger longValue()用法及代码示例
- Java DoubleAccumulator longValue()用法及代码示例
- Java AtomicLong longValue()用法及代码示例
- Java Number.longValue()用法及代码示例
- Java Byte longValue()用法及代码示例
- Java LongMath.divide(long, long, RoundingMode)用法及代码示例
- Java LongMath.checkedAdd(long a, long b)用法及代码示例
- Java Longs.checkedSubtract(long a, long b)用法及代码示例
- Java Longs.indexOf(long[] array, long target)用法及代码示例
注:本文由纯净天空筛选整理自ankita_chowrasia大神的英文原创作品 Long longValue() Method in Java。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。