long在java哪个包里_Java.lang Long

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值