现在的位置: 首页 > 综合 > 正文

java包装类

2017年09月13日 ⁄ 综合 ⁄ 共 642字 ⁄ 字号 评论关闭

 

           java中一切皆对象,所以对基本数据类型进行了包装。

 

 

public class IntegerDemo01{
	public static void main(String args[]){
		int i = 10 ;
		Integer i2 = new Integer(i) ;	// 装箱操作
		int j = i2.intValue() ;		// 拆箱操作
		System.out.println(j * j) ;
	}
};

jdk1.5以后,就可以进行自动拆箱和装箱。

 

public class IntegerDemo02{
	public static void main(String args[]){
		int i = 10 ;
		Integer i2 = i ;	// 自动装箱操作
		int j = i2 ;		// 自动拆箱操作
		System.out.println(j * j) ;
	}
};

 

 

public class IntegerDemo03{
	public static void main(String args[]){
		System.out.println(Integer.MAX_VALUE) ;
		System.out.println(Integer.MIN_VALUE) ;
	}
};

 

 

public class IntegerDemo04{
	public static void main(String args[]){
		String str = "12sss3" ;	// 字符串由数字组成
		int i = Integer.parseInt(str) ;	// 将字符串变为int型
		System.out.println(i++) ;
	}
};

 

【上篇】
【下篇】

抱歉!评论已关闭.