Java.lang Long
1 Java.lang Long介绍
java.lang.Long 类封装了基本类型long对象的值。 long类型的对象包含单个字段类型为long。
2 Java.lang Long声明
public final class Long
extends Number
implements Comparable
3 Java.lang Long方法
4 Java.lang Long案例1
package com.yiidian;
/**
* 一点教程网: http://www.yiidian.com
*/
public class JavaLongExample1 {
public static void main(String[] args) {
Long x1=67l;
Long x2=98l;
Long x3=6l;
// Compares two long values.
int b1 = Long.compare(x1, x2);
if(b1==0)
{
System.out.println("Both '"+x1+"' and '"+ x2+"' are same");
}
else if(b1>0)
{
System.out.println(x1+" is greater than "+x2);
}
else
{
System.out.println(x1+" is smaller than "+x2);
}
// Returns the hashcode for the given long value.
System.out.println("The hashcode for the value '"+x1+"' is given as :"+x1.hashCode());
// Returns the value of long in the form of short.
short b2 = x3.shortValue();
System.out.println("The short value for '"+x2+"' is given as : "+b2);
}
}
输出结果为:
67 is smaller than 98
The hashcode for the value '67' is given as :67
The short value for '98' is given as : 6
5 Java.lang Long案例2
package com.yiidian;
/**
* 一点教程网: http://www.yiidian.com
*/
public class JavaLongExample2 {
public static void main(String [] args) {
Long x1= 45l;
Long x2= 67l;
Long x3= 12l;
// Adds the two values.
System.out.println("The sum of '"+x1+ "' and '"+x2+"' 'is given as :"+Long.sum(x1, x2));
// Returns the value by reversing the order of nits in 2's complement.
System.out.println("The reverse value for'" +x3+ "' is given as :"+Long.reverse(x3));
// Returns the string representation.
String obj = x2.toString();
System.out.println("The string representation for '" +x2+ "' is given as : "+obj);
}
}
输出结果为:
The sum of '45' and '67' 'is given as :112
The reverse value for'12' is given as :3458764513820540928
The string representation for '67' is given as : 67