杰点

hello java

基本数据类型的装箱和拆箱

 

 1 //装箱 拆箱 享元模式
 2 public class flyWeight {
 3 
 4     public static void main(String[] args){
 5     Integer i=1127//装箱 将基本数据类型转换为对象 
 6     System.out.println(i+3);//拆箱 将对象转换为基本类型
 7     
 8     Integer i2=127;
 9     Integer i3=127;
10     Integer i4=128;
11     Integer i5=128;
12     System.out.println(i2==i3);//true   享元模式
13     System.out.println(i4==i5);//false  享元模式 将小的数据 -128~127 共享一个对象
14     
15     String str1="abcds";
16     String str2="abcds";
17     System.out.println(str1==str2); //true 享元模式
18     }
19 }
20 

posted on 2010-12-29 13:08 杰点 阅读(128) 评论(0)  编辑  收藏 所属分类: JAVA


只有注册用户登录后才能发表评论。


网站导航:
 
<2025年7月>
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

导航

统计

留言簿

文章分类

文章档案

搜索

最新评论