基本类型包装类、应用、相互转换、装箱拆箱操作

基本包装类表

基本数据类型基本包装类
byteByte
shortShort
intInteger
longLong
floatFloat
doubleDouble
charcharacter
booleanBoolean

Integer

java.lang.Number
	java.lang.Integer
public final class Integer 
				  extends Number 
				  implements Comparable<Integer>              //Comparable比较器

Integer中的常用方法

方法名作用
static String Integer.toBinaryString(int i)将 i 转换为二进制字符串
static String Integer.toHexString(int i)将 i 转换为十六进制字符串
static Integer.valueOf(int i)返回表示指定的int值的Integer实例
* 判断int类型是否溢出的一种方法:
	如果一个int值已经大于了Integer.MAXVALUE/10,或者int值等于Integer.MAXVALUE且接下来要加的值大于7则内存溢出。(Integer.MAXVALUE=2137483647)

常用方法例子:

Integer.valueOf(int i)得到对象:
Integer i1=Integer.valueOf(100);  //手动装箱
Integer i2=100//自动装箱
-------------------------------------------------------------------------------------------------Integer.valueOf(String s)得到Integer对象:
Integer i3=Integer.valueOf(new String("100"));      //手动装箱(该方法中只能是数字String类型)
Integer i4="100";        //自动装箱
-------------------------------------------------------------------------------------------------
String -> int 转换类型方法:
	方法一:
Integer i5=Integer.valueOf(new String("100"));
int i=i5.intValue();  //手动拆箱
//int i=i5;  自动拆箱也可以
	方法二:
String s="1234567890";
int i=Integer.parseInt(s);  //推荐此方法
int -> String 转换类型方法:
int i=1234567890;
String s=String.valueOf(i);

注:基本类型包装类基本都有Double parseDouble(String s);方法,用于将字符串转换为其他类型

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值