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