> 文档中心 > long(Long)与int(Integer)四种类型之间互相转换的方法分享

long(Long)与int(Integer)四种类型之间互相转换的方法分享

最近开发的项目,里面的金额比较大,经常有long型 ,int型,那么他们之间怎么转换呢?

下文笔者将一一道来,如下所示:

一.将long型转化为int型,此处的long型是基础类型

long a = 8989; int b = (int)a;

二.将Long型转换为int 型的,此处的Long型是包装类型:

Long a = 8989; int b=a.intValue();

三.将int型转化为long型,此处的int型是基础类型:

int a = 8989;long b = (int)a;

四.将Integer型转化为long型,此处的Integer型是包装类型:

int a = 8989;Long b = a.longValue();

 以上笔者进行了包装类型和基础类型的相互转换
 

闲鱼礼物网