码迷,mamicode.com
首页 > 编程语言 > 详细

Java Integer为代表的包装类

时间:2017-02-21 13:27:28      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:...   print   compare   模式   hashcode   table   返回   转化   oat   

Java种的Integer是int的包装类型

 

1. Integer 是int的包装类型,数据类型是类,初值为null

 

2. 初始化时

  

int i = 1;
Integer i = new Integer(1);

3.  类的自动装箱与自动拆箱

  1)自动装箱

Integer i = new Integer(1);    //使用正常的声明方法
Integer i = 1;    //使用自动装箱

  2)自动拆箱

Integer num = 10;      //自动装箱
System.out.print(num--);    //自动拆箱

  3)自动拆箱与装箱中的享元模式

  -128~128(8bit数字)的值,被装箱之后内存将会复用,(即不同名称8bit数字的变量在内存中是相同的)

  -128~127之外的数字,每次声明都新建一个对象,因此即使拆箱数值相同,装箱后的对象是不相等的(==结果为false)

4. Java中的包装类们

  1)包装类是final型的

  2)包装类支持变量转化

byte java.lang.Byte
boolean java.lang.Boolean
short java.lang.Short
char java.lang.Charactor
int java.lang.Integer
long java.lang.Long
float java.lang.Float
double java.lang.Double

5. Integer类的方法

  1)构造方法

Integer(int value)        //使用数字
Integer(String s)          //使用String表示的数字

  2)方法

返回值 名称 功能
类型转换    
byte byteValue() 返回byte类型
double doubleValue() 返回double类型
float floatValue() ...
int intValue()  
long longValue()  
short shortValue()  
String    
String toString() 表示该值的String对象
static String toString(int i) 表示指定整数的String对象
static String toString(int i, int radix) 表示指定基数的整数String对象
static String toBinaryString(int i) 二进制无符号字符串
static String toHexString(int i) 十六进制无符号字符串
static String toOctalString(int i) 八进制无符号字符串
static int parseInt(String s) 将字符串转化为整数
static int  reverse(int i) 反转二进制补码的位的顺序
static int rotateLeft() 循环左移
static int  rotateRight()  
int hashCode() 返回哈希码
int compareTo(Integer) 比较两个Integerd的数值
     

 

Java Integer为代表的包装类

标签:...   print   compare   模式   hashcode   table   返回   转化   oat   

原文地址:http://www.cnblogs.com/liutianchen/p/6423606.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!