Java中Integer類的詳解與用途

來源:互聯網
上載者:User

標籤:java   integer   類   詳解   用途   

java.lang
類 Integer

java.lang.Object

  java.lang.Number

      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 中提取的值。

 

Java中Integer類的詳解與用途

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.