1. 程式人生 > >Java中Integer類的方法

Java中Integer類的方法

java.lang.Integer

所有已實現的介面:

Serializable, Comparable<Integer>

public final class Integer

extends Number

implements Comparable<Integer>

Integer 類在物件中包裝了一個基本型別 int 的值。Integer 型別的物件包含一個 int 型別的欄位。

此外,該類提供了多個方法,能在 int 型別和 String 型別之間互相轉換,還提供了處理 int 型別時非常有用的其他一些常量和方法。

實現注意事項:“bit twiddling”方法(如 highestOneBit 和 numberOfTrailingZeros)的實現基於 Henry S. Warren, Jr.撰寫的《Hacker's Delight

》(Addison Wesley, 2002)中的一些有關材料。

從以下版本開始:

JDK1.0

另請參見:

序列化表格

欄位摘要

static int

MAX_VALUE 
          保持 int 型別的最大值的常量可取的值為 231-1。

static int

MIN_VALUE 
          保持 int 型別的最小值的常量可取的值為 -231

static int

SIZE 
          以二進位制補碼形式表示 int 值的位數。

static Class<Integer>

TYPE 
          表示基本型別 int 的 Class 例項。

構造方法摘要

Integer(int value) 
          構造一個新分配的 Integer 物件,它表示指定的 int 值。

Integer(String s) 
          構造一個新分配的 Integer 物件,它表示 String 引數所指示的 int 值。

方法摘要

static int

bitCount(int i) 
          返回指定 int 值的二進位制補碼錶示形式的 1 位的數量。

 byte

byteValue() 
          以 byte 型別返回該 Integer 的值。

 int

compareTo(Integer anotherInteger) 
          在數字上比較兩個 Integer 物件。

static Integer

decode(String nm) 
          將 String 解碼為 Integer。

 double

doubleValue() 
          以 double 型別返回該 Integer 的值。

 boolean

equals(Object obj) 
          比較此物件與指定物件。

 float

floatValue() 
          以 float 型別返回該 Integer 的值。

static Integer

getInteger(String nm) 
          確定具有指定名稱的系統屬性的整數值。

static Integer

getInteger(String nm, int val) 
          確定具有指定名稱的系統屬性的整數值。

static Integer

getInteger(String nm, Integer val) 
          返回具有指定名稱的系統屬性的整數值。

 int

hashCode() 
          返回此 Integer 的雜湊碼。

static int

highestOneBit(int i) 
          返回具有至多單個 1 位的 int 值,在指定的 int 值中最高位(最左邊)的 1 位的位置。

 int

intValue() 
          以 int 型別返回該 Integer 的值。

 long

longValue() 
          以 long 型別返回該 Integer 的值。

static int

lowestOneBit(int i) 
          返回具有至多單個 1 位的 int 值,在指定的 int 值中最低位(最右邊)的 1 位的位置。

static int

numberOfLeadingZeros(int i) 
          在指定 int 值的二進位制補碼錶示形式中最高位(最左邊)的 1 位之前,返回零位的數量。

static int

numberOfTrailingZeros(int i) 
          返回指定的 int 值的二進位制補碼錶示形式中最低(“最右”)的為 1的位後面的零位個數。

static int

parseInt(String s) 
          將字串引數作為有符號的十進位制整數進行分析。

static int

parseInt(String s, int radix) 
          使用第二個引數指定的基數,將字串引數解析為有符號的整數。

static int

reverse(int i) 
          返回通過反轉指定 int 值的二進位制補碼錶示形式中位的順序而獲得的值。

static int

reverseBytes(int i) 
          返回通過反轉指定 int 值的二進位制補碼錶示形式中位元組的順序而獲得的值。

static int

rotateLeft(int i, int distance) 
          返回根據指定的位數迴圈左移指定的 int 值的二進位制補碼錶示形式而得到的值。

static int

rotateRight(int i, int distance) 
          返回根據指定的位數迴圈右移指定的 int 值的二進位制補碼錶示形式而得到的值。

 short

shortValue() 
          以 short 型別返回該 Integer 的值。

static int

signum(int i) 
          返回指定 int 值的符號函式。

static String

toBinaryString(int i) 
          以二進位制(基數 2)無符號整數形式返回一個整數引數的字串表示形式。

static String

toHexString(int i) 
          以十六進位制的無符號整數形式返回一個整數引數的字串表示形式。

static String

toOctalString(int i) 
          以八進位制(基數 8)無符號整數形式返回一個整數引數的字串表示形式。

 String

toString() 
          返回一個表示該 Integer 值的 String 物件。

static String

toString(int i) 
          返回一個表示指定整數的 String 物件。

static String

toString(int i, int radix) 
          用第二個引數指定的基數返回第一個引數的字串表示形式。

static Integer

valueOf(int i) 
          返回一個表示指定的 int 值的 Integer 例項。

static Integer

valueOf(String s) 
          返回保持指定的 String 的值的 Integer 物件。

static Integer

valueOf(String s, int radix) 
          返回一個 Integer 物件,該物件中保持了用第二個引數提供的基數進行分析時從指定的 String 中提取的值。