包装类
(jdk1.5自动装箱/自动拆箱)
包装类可以把基本类型包装对象类型
12       new Integer(12)
- java当中的包装类
 案例: integer1.Demo4
 方法:Long.parseLong("13552329647"):把一个String自动
 转化为long类型的数据
- jdk1.5 自动装箱和自动拆箱
 自动装箱:自动帮我们把数据变成包装类对象
 自动拆箱:自动把包装类对象转化为数据
 一般比较早的项目,很多是jdk1.4,eg:list.add(new Integer(2));
1)共有8种包装类
Int
Integer
Long
Long
Byte
Byte
Short
Short
Float
Float
Double
Double
Boolean
Boolean
Char
character
2)包装类提供了对于数据类型的工具方法
例如:
Integer.tohexstring()
Integer.tostring(int)
3)自动包装(auto boxing/unboxing)
java5以后可以
4)注意点
包装类时final的类
包装类对象是不变的,与字符串类似
Integer a = 1;
Integer b = 2;
a = a+b;
a = new Integer(a.intValue() + b.intValue();
包装类覆盖了toString() equals() hashcode() compareto()方法
 
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号