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);
primitive type:wrapped type
最新推荐文章于 2021-04-02 20:59:31 发布