`
trix
  • 浏览: 82362 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

primitive type:wrapped type

JVM 
阅读更多
primitive type: 基本类型,像int、double就是。
wrapped type:包装类型,int—>Integer,double—>Decimal

基本类型跟就是不可实例化的,可以直接初始化、赋值、运算。不可调用方法,不可放入容器(要求必须是类实例才行)。
int i=10;
i++;

包装类型就是把基本类型变成一个类实例,一定要new才产生,可以调用方法,可以放入容器。
int tt=100;
tt++;
Integer kk=new Integer(tt); //tt的包装类实例
System.out.println(kk.intValue()); //还是101
HashMap m=new HashMap();
m.put("abc",kk);

String是特殊的,可以像基本类型这样用,但其实它是类实例来的,可以调用它的方法,也可以放入到容器里面。JVM对String作了特殊处理。
String s="123456";
System.out.println(s.substring(0,1));
HashMap m=new HashMap();
m.put("abc",s); 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics