Java自动装箱与自动拆箱

package com.heilong.other;
/*
 * 
 * jdk1.5新特性------>自动装箱与自动拆箱
 * 
 * 
 * java是面向对象的语言,任何事物都可以使用类进行描述,sun就使用了一些类描述了java中的八种基本数据类型
 * 
 *   基本数据类型			包装类型
 * 		byte				  Byte
 * 		short				  Short
 * 		int                   Integer
 * 		long				  Long
 * 
 * 		float                 Float
 * 		double                Double
 * 		
 * 		boolean				  Boolean
 * 
 * 		char                  Character
 * 
 * 
 * 基本数据类型有了对应包装类型的好处:
 * 1.
 * 
 * 
 * */
public class Demo5 {

	public static void main(String[] args) {
		String str = "12";
		//字符串转换成int类型数据。可以把字符串转换成对应数字
		int i = Integer.parseInt(str);
		System.out.println(i);
		
		//把数字转换成字符串
		System.out.println(Integer.toString(i));
		
		//自动装箱:自动把java的基本数据类型转换成对象数据类型
		int temp = 10;
		Integer b = temp;
		
		//自动拆箱:把引用数据类型转换成基本数据类型
		Integer c = new Integer(13);
		int d = c;
		System.out.println(d);
	}

}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值