Integer 基本数据类型int 的包装类
Integer 类型的对象包含一个 int 类型的字段
属性简介
值为 2^31-1 的常量,它表示 int 类型能够表示的最大值 | @Native public static final int MAX_VALUE = 0x7fffffff; |
值为 -2^31 的常量,它表示 int 类型能够表示的最小值 | @Native public static final int MIN_VALUE = 0x80000000; |
用来以二进制补码形式表示 int 值的比特位数 | @Native public static final int SIZE = 32; |
二进制补码形式表示 int 值的字节数 | public static final int BYTES = SIZE / Byte.SIZE; |
表示基本类型 int 的 Class 实例 | public static final Class<Integer> TYPE = (Class<Integer>) Class.getPrimitiveClass("int"); |
构造方法
构造方法都是新创建对象,分配新的空间
字符串形式构造,默认以十进制的字符串形式解析
包装类 使用对应的基本数据类型int 构造 | |
包装类 使用对应的基本数据类型int的字符串String形式构造 |
常用方法
比较
parseXXX系列
字符串解析 为 基本类型,
不需要对象,所以都是静态方法
valueOf系列
把基本基本类型 包装为对象
用来创建获得对象,所以无需对象,全都是静态方法
VaueOf系列都有对应的缓存区, 缓存区范围内对象为同一个
缓冲区为静态内部类中的数组
缓冲范围为 -128~127
decode
接受通过以下语法给出的十进制、十六进制和八进制数字 Sign是可选的 再往后就是指定基数的字符序列的正值,不能是负数,想要设置负数请仅仅使用符号位 也就是+-1 --1这种肯定不行 |
Sign DecimalNumeral Sign 0x HexDigits Sign 0X HexDigits Sign # HexDigits Sign 0 OctalDigits Sign: - + |
XXXValue系列
获取对象的某种基本类型的值
需要获取对象的所以必然全部都是实例方法
强制类型转换的形式,将内部的int值转换为指定的类型
byte byteValue() | |
short shortValue() | |
int intValue() | |
long longValue() | |
float floatValue() | |
double doubleValue() |
toUnsignedXXX 系列
无符号相关的转换
toString toXXXString 系列
根本都是为了转换为字符串形式
内部有一个私有方法用于转换为无符号形式
equals
Integer重写了equals方法 比较的是两个Integer对象中内部的 int value值 |
hashCode
static int hashCode(int value) | 静态方法 返回某个int 数值的hashcode |
int hashCode() | 实例方法 获取某个Integer对象的hashcode 等同于static int hashCode(int value) 调用 内部value值 |
getXXX系列
获取系统属性的数值
其他方法
最高1 位 最低1 位 前置零个数 和 后置0个数 | highestOneBit(int) / lowestOneBit(int) numberOfLeadingZeros(int) / numberOfTrailingZeros(int) |
位数 循环左移/循环右移 按位翻转 按照字节翻转 | bitCount(int) 返回二进制补码表示形式的 1 位的数量,不是全部位数 rotateLeft(int, int) / rotateRight(int, int) reverse(int) / reverseBytes(int) |
取整 求余 | divideUnsigned(int, int) remainderUnsigned(int, int) |
Integer还提供了上面几个方法,在开篇中已经描述 Long也有提供
语义一致
static int signum(int i) | 静态方法 返回指定 int 值的符号函数 (如果指定值为负,则返回 -1;如果指定值为零,则返回 0;如果指定的值为正,则返回 1 ) |
static int sum(int a, int b) | 静态方法 求和 |
static int max(int a, int b) | 静态方法 最大值 |
static int min(int a, int b) | 静态方法 最小值 |