JDK1.8 API翻譯(第四彈:Integer)

API文檔鏈接如下:
https://docs.oracle.com/javase/8/docs/api/java/lang/Integer.html

下面開始翻譯。

Class Integer

java.lang.Object
    java.lang.Number
        java.lang.Integer
All Implemented Interfaces:
Serializable, Comparable<Integer>

public final class Integer
extends Number
implements Comparable<Integer>

The Integer class wraps a value of the primitive type int in an object. An object of type Integer contains a single field whose type is int.
In addition, this class provides several methods for converting an int to a String and a String to an int, as well as other constants and methods useful when dealing with an int.

Implementation note: The implementations of the “bit twiddling” methods (such as highestOneBit and numberOfTrailingZeros) are based on material from Henry S. Warren, Jr.’s Hacker’s Delight, (Addison Wesley, 2002).

Integer類是把一個原始類型int的值包裝到一個類中。Integer類的對象包含一個int類型的字段。
此外,該類還提供了一些將int轉換爲String和String轉換爲int的方法,以及在處理int時有用的其他常量和方法。

實現說明:“bit twiddling”方法(如highestOneBit和numberOfTrailingZeros)的實現是基於Henry S. Warren, Jr.’s Hacker’s Delight, (Addison Wesley, 2002)的內容。

Since:
JDK1.0
See Also:
Serialized Form

Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait

Field Detail字段詳細信息

MIN_VALUE

@Native
public static final int MIN_VALUE

A constant holding the minimum value an int can have, -231.
一個常量,表示int可以具有的最小值,-2的31次方。
See Also:
Constant Field Values

MAX_VALUE

@Native
public static final int MAX_VALUE

A constant holding the maximum value an int can have, 231-1.
一個常量,表示int可以具有的最大值,2的31次方-1。
See Also:
Constant Field Values

TYPE

public static final Class<Integer> TYPE
The Class instance representing the primitive type int.
表示原始類型int的類實例。
Since:
JDK1.1

SIZE

@Native
public static final int SIZE

The number of bits used to represent an int value in two’s complement binary form.
二進制補碼形式的int值的位數。
Since:
1.5
See Also:
Constant Field Values

BYTES

public static final int BYTES
The number of bytes used to represent a int value in two’s complement binary form.
二進制補碼形式int值的字節數。
Since:
1.8
See Also:
Constant Field Values

Constructor Detail構造方法詳細信息

Integer

public Integer(int value)
Constructs a newly allocated Integer object that represents the specified int value.
構造一個新分配的Integer對象,表示指定的int值。
Parameters:
value - the value to be represented by the Integer object.
value - 由Integer對象表示的值。

Integer

public Integer(String s) throws NumberFormatException
Constructs a newly allocated Integer object that represents the int value indicated by the String parameter. The string is converted to an int value in exactly the manner used by the parseInt method for radix 10.
構造一個新分配的Integer對象,表示由String參數指明的int值。字符串轉換爲int值的方式與10進制的parseInt方法一樣。
Parameters:
s - the String to be converted to an Integer.
s - 用來轉換爲Integer的字符串
Throws:
NumberFormatException - if the String does not contain a parsable integer.
如果字符串不包含可轉換的整數。
See Also:
parseInt(java.lang.String, int)

Method Detail方法詳細信息

toString

public static String toString(int i, int radix)
Returns a string representation of the first argument in the radix specified by the second argument.
返回第一個參數的字符串表示形式,由第二個參數指定進制數。

If the radix is smaller than Character.MIN_RADIX or larger than Character.MAX_RADIX, then the radix 10 is used instead.
如果進制數小於Character.MIN_RADIX或大於Character.MAX_RADIX,則使用10進制 。

If the first argument is negative, the first element of the result is the ASCII minus character ‘-’ ('\u002D'). If the first argument is not negative, no sign character appears in the result.
如果第一個參數爲負,結果的第一個元素是ASCII碼減號’-‘('\u002D')。如果第一個參數不爲負,則結果中不會出現符號字符。

The remaining characters of the result represent the magnitude of the first argument. If the magnitude is zero, it is represented by a single zero character ‘0’ ('\u0030'); otherwise, the first character of the representation of the magnitude will not be the zero character. The following ASCII characters are used as digits:
結果的剩餘字符表示第一個參數的數值。如果數值爲零,則由單個零字符’0’('\u0030')表示;否則,表示數值的第一個字符就不是零字符。以下ASCII字符可用作數字:

0123456789abcdefghijklmnopqrstuvwxyz

These are '\u0030' through '\u0039' and '\u0061' through '\u007A'. If radix is N, then the first N of these characters are used as radix-N digits in the order shown. Thus, the digits for hexadecimal (radix 16) are 0123456789abcdef. If uppercase letters are desired, the String.toUpperCase() method may be called on the result:
這些是'\u0030''\u0039''\u0061''\u007A'。如果進制數是N,則按顯示順序,這些字符的前N個用作N進制的數字。因此,十六進制(進制數16)的數字是0123456789abcdef。如果需要大寫字母,可以對結果調用String.toUpperCase()方法:

Integer.toString(n, 16).toUpperCase()

Parameters:
i - an integer to be converted to a string.
i - 要轉換爲字符串的整數。
radix - the radix to use in the string representation.
radix - 在字符串表示中使用的進制數。

Returns:
a string representation of the argument in the specified radix.
參數按指定進制數的字符串表示形式。

See Also:
Character.MAX_RADIX, Character.MIN_RADIX

toUnsignedString

public static String toUnsignedString(int i, int radix)
Returns a string representation of the first argument as an unsigned integer value in the radix specified by the second argument.
返回第一個無符號整數值參數的字符串表示形式,第二個參數表示進制數。

If the radix is smaller than Character.MIN_RADIX or larger than Character.MAX_RADIX, then the radix 10 is used instead.
如果進制數小於Character.MIN_RADIX或大於Character.MAX_RADIX,則使用進制數10 。

Note that since the first argument is treated as an unsigned value, no leading sign character is printed.
注意,由於第一個參數被視爲無符號值,因此不會打印前導符號。

If the magnitude is zero, it is represented by a single zero character ‘0’ ('\u0030'); otherwise, the first character of the representation of the magnitude will not be the zero character.
如果數值爲零,則由單個零字符’0’('\u0030')表示;否則,表示數值的第一個字符就不是零字符。

The behavior of radixes and the characters used as digits are the same as toString.
進制數和用作數字的字符與toString相同。

Parameters:
i - an integer to be converted to an unsigned string.
i - 要轉換爲無符號字符串的整數。
radix - the radix to use in the string representation.
radix - 在字符串表示中使用的進制數。

Returns:
an unsigned string representation of the argument in the specified radix.
參數按指定進制數的無符號字符串表示形式。

Since:
1.8
See Also:
toString(int, int)

toHexString

public static String toHexString(int i)
Returns a string representation of the integer argument as an unsigned integer in base 16.
返回參數的字符串表示形式,參數爲無符號整數,使用base 16。

The unsigned integer value is the argument plus 232 if the argument is negative; otherwise, it is equal to the argument. This value is converted to a string of ASCII digits in hexadecimal (base 16) with no extra leading 0s.
如果參數爲負,則無符號整數值爲參數加2的32次方;否則,它等於參數。該值轉換爲十六進制(base16)的ASCII數字字符串,沒有額外的前導0。

The value of the argument can be recovered from the returned string s by calling Integer.parseUnsignedInt(s, 16).
參數的值可以通過調用Integer.parseUnsignedInt(s, 16)從返回的字符串s中來恢復。

If the unsigned magnitude is zero, it is represented by a single zero character ‘0’ ('\u0030'); otherwise, the first character of the representation of the unsigned magnitude will not be the zero character. The following characters are used as hexadecimal digits:
如果無符號數值爲零,則由單個零字符’0’('\u0030')表示;否則,表示無符號數值的第一個字符就不是零字符。以下字符用作十六進制數字:

0123456789abcdef

These are the characters '\u0030' through '\u0039' and '\u0061' through '\u0066'. If uppercase letters are desired, the String.toUpperCase() method may be called on the result:
這些字符是從’\u0030’到’\u0039’和從’\u0061’到’\u0066’。如果需要大寫字母,可以對結果調用String.toUpperCase()方法:

Integer.toHexString(n).toUpperCase()

Parameters:
i - an integer to be converted to a string.
i - 要轉換爲字符串的整數。

Returns:
the string representation of the unsigned integer value represented by the argument in hexadecimal (base 16).
由參數以十六進制(base 16)表示的無符號整數值的字符串形式。

Since:
JDK1.0.2
See Also:
parseUnsignedInt(String, int), toUnsignedString(int, int)

toOctalString

public static String toOctalString(int i)
Returns a string representation of the integer argument as an unsigned integer in base 8.
返回參數的字符串表示形式,參數爲無符號整數,使用base 8。

The unsigned integer value is the argument plus 232 if the argument is negative; otherwise, it is equal to the argument. This value is converted to a string of ASCII digits in octal (base 8) with no extra leading 0s.
如果參數爲負,則無符號整數值爲參數加2的32次方;否則,它等於參數。該值轉換爲八進制(base8)的ASCII數字字符串,沒有額外的前導0。

The value of the argument can be recovered from the returned string s by calling Integer.parseUnsignedInt(s, 8).
參數的值可以通過調用Integer.parseUnsignedInt(s, 8)從返回的字符串s中來恢復。

If the unsigned magnitude is zero, it is represented by a single zero character ‘0’ ('\u0030'); otherwise, the first character of the representation of the unsigned magnitude will not be the zero character. The following characters are used as octal digits:
如果無符號數值爲零,則由單個零字符’0’('\u0030')表示;否則,表示無符號數值的第一個字符就不是零字符。以下字符用作八進制數字:

01234567

These are the characters '\u0030' through '\u0037'.
這些字符是從'\u0030''\u0037'

Parameters:
i - an integer to be converted to a string.
i - 要轉換爲字符串的整數。

Returns:
the string representation of the unsigned integer value represented by the argument in octal (base 8).
由參數以八進制(base 8)表示的無符號整數值的字符串形式。

Since:
JDK1.0.2
See Also:
parseUnsignedInt(String, int), toUnsignedString(int, int)

toBinaryString

public static String toBinaryString(int i)
Returns a string representation of the integer argument as an unsigned integer in base 2.
返回參數的字符串表示形式,參數爲無符號整數,使用base 2。

The unsigned integer value is the argument plus 232 if the argument is negative; otherwise it is equal to the argument. This value is converted to a string of ASCII digits in binary (base 2) with no extra leading 0s.
如果參數爲負,則無符號整數值爲參數加2的32次方;否則,它等於參數。該值轉換爲二進制(base2)的ASCII數字字符串,沒有額外的前導0。

The value of the argument can be recovered from the returned string s by calling Integer.parseUnsignedInt(s, 2).
參數的值可以通過調用Integer.parseUnsignedInt(s, 2)從返回的字符串s中來恢復。

If the unsigned magnitude is zero, it is represented by a single zero character ‘0’ ('\u0030'); otherwise, the first character of the representation of the unsigned magnitude will not be the zero character. The characters ‘0’ ('\u0030') and ‘1’ ('\u0031') are used as binary digits.
如果無符號數值爲零,則由單個零字符’0’('\u0030')表示;否則,表示無符號數值的第一個字符就不是零字符。字符’0’ ('\u0030')和’1’ ('\u0031')用作二進制數字。

Parameters:
i - an integer to be converted to a string.
i - 要轉換爲字符串的整數。

Returns:
the string representation of the unsigned integer value represented by the argument in binary (base 2).
由參數以二進制(base 2)表示的無符號整數值的字符串形式。

Since:
JDK1.0.2
See Also:
parseUnsignedInt(String, int), toUnsignedString(int, int)

toString

public static String toString(int i)
Returns a String object representing the specified integer. The argument is converted to signed decimal representation and returned as a string, exactly as if the argument and radix 10 were given as arguments to the toString(int, int) method.
返回表示指定整數的String對象。參數被轉換爲帶符號的十進制表示形式,並作爲字符串返回,就像toString(i, 10)方法一樣。

Parameters:
i - an integer to be converted.
i - 要轉換爲字符串的整數。

Returns:
a string representation of the argument in base 10.
由參數以十進制(base 10)表示的字符串形式。

toUnsignedString

public static String toUnsignedString(int i)
Returns a string representation of the argument as an unsigned decimal value. The argument is converted to unsigned decimal representation and returned as a string exactly as if the argument and radix 10 were given as arguments to the toUnsignedString(int, int) method.
返回將參數的字符串表示形式,該參數爲無符號十進制。參數被轉換爲無符號十進制表示形式,並作爲字符串返回,就像toUnsignedString(i, 10)方法一樣。

Parameters:
i - an integer to be converted to an unsigned string.
i - 要轉換爲字符串的整數。

Returns:
an unsigned string representation of the argument.
參數的無符號字符串形式。

Since:
1.8
See Also:
toUnsignedString(int, int)

parseInt

public static int parseInt(String s, int radix) throws NumberFormatException
Parses the string argument as a signed integer in the radix specified by the second argument. The characters in the string must all be digits of the specified radix (as determined by whether Character.digit(char, int) returns a nonnegative value), except that the first character may be an ASCII minus sign ‘-’ ('\u002D') to indicate a negative value or an ASCII plus sign ‘+’ ('\u002B') to indicate a positive value. The resulting integer value is returned.
將字符串參數轉換爲有符號整數,以第二個參數指定進制數。字符串中的字符必須全部是指定進制數的數字(由Character.digit(char, int)是否返回非負值來確定),除了第一個字符可能是表示負值的ASCII減號’-‘('\u002D')或表示正值的ASCII加號’+’('\u002B')。返回所得到的整數值。

An exception of type NumberFormatException is thrown if any of the following situations occurs:
如果發生以下任何一種情況,則拋出NumberFormatException異常:

The first argument is null or is a string of length zero.
The radix is either smaller than Character.MIN_RADIX or larger than Character.MAX_RADIX.
Any character of the string is not a digit of the specified radix, except that the first character may be a minus sign ‘-’ ('\u002D') or plus sign ‘+’ ('\u002B') provided that the string is longer than length 1.
The value represented by the string is not a value of type int.
第一個參數是null或是長度爲零的字符串。
進制數小於Character.MIN_RADIX或大於Character.MAX_RADIX
字符串的任何一個字符不是指定進制數的數字,除了第一個字符可能是減號’-‘('\u002D')或加號’+’('\u002B'),前提是字符串長度大於1。
由字符串表示的值不是int類型的值。

Examples:
例如:

parseInt("0", 10) returns 0
parseInt("473", 10) returns 473
parseInt("+42", 10) returns 42
parseInt("-0", 10) returns 0
parseInt("-FF", 16) returns -255
parseInt("1100110", 2) returns 102
parseInt("2147483647", 10) returns 2147483647
parseInt("-2147483648", 10) returns -2147483648
parseInt("2147483648", 10) throws a NumberFormatException
parseInt("99", 8) throws a NumberFormatException
parseInt("Kona", 10) throws a NumberFormatException
parseInt("Kona", 27) returns 411787

Parameters:
s - the String containing the integer representation to be parsed
s -包含要被轉換的整數的字符串

radix - the radix to be used while parsing s.
radix - 轉換s時使用的進制數。

Returns:
the integer represented by the string argument in the specified radix.
以指定進制數的字符串參數表示的整數。

Throws:
NumberFormatException - if the String does not contain a parsable int.
NumberFormatException - 如果字符串不包含可解析的int。

parseInt

public static int parseInt(String s) throws NumberFormatException
Parses the string argument as a signed decimal integer. The characters in the string must all be decimal digits, except that the first character may be an ASCII minus sign ‘-’ ('\u002D') to indicate a negative value or an ASCII plus sign ‘+’ ('\u002B') to indicate a positive value. The resulting integer value is returned, exactly as if the argument and the radix 10 were given as arguments to the parseInt(java.lang.String, int) method.
將字符串參數轉換爲十進制有符號整數。字符串中的字符必須全部是十進制數的數字,除了第一個字符可能是表示負值的ASCII減號’-‘('\u002D')或表示正值的ASCII加號’+’('\u002B')。返回所得到的整數值,就像parseInt(s, 10)方法一樣。

Parameters:
s - a String containing the int representation to be parsed
s -包含要被轉換的整數的字符串

Returns:
the integer value represented by the argument in decimal.
十進制參數表示的整數。

Throws:
NumberFormatException - if the string does not contain a parsable integer.
NumberFormatException - 如果字符串不包含可解析的int。

parseUnsignedInt

public static int parseUnsignedInt(String s, int radix) throws NumberFormatException
Parses the string argument as an unsigned integer in the radix specified by the second argument. An unsigned integer maps the values usually associated with negative numbers to positive numbers larger than MAX_VALUE. The characters in the string must all be digits of the specified radix (as determined by whether Character.digit(char, int) returns a nonnegative value), except that the first character may be an ASCII plus sign ‘+’ ('\u002B'). The resulting integer value is returned.
將字符串參數解析爲無符號整數,以第二個參數指定進制數。字符串中的字符必須是指定進制數的數字(取決於Character.digit(char, int)是否返回一個非負的值),除了第一個字符可以是ASCII加符號’+’('\u002B')。返回所得到的整數值。

An exception of type NumberFormatException is thrown if any of the following situations occurs:
如果發生以下任何一種情況,則拋出NumberFormatException異常:

The first argument is null or is a string of length zero.
The radix is either smaller than Character.MIN_RADIX or larger than Character.MAX_RADIX.
Any character of the string is not a digit of the specified radix, except that the first character may be a plus sign ‘+’ ('\u002B') provided that the string is longer than length 1.
The value represented by the string is larger than the largest unsigned int, 232-1.
第一個參數是null或是長度爲零的字符串。
進制數小於Character.MIN_RADIX或大於Character.MAX_RADIX
字符串的任何一個字符不是指定進制數的數字,除了第一個字符可能是加號’+’('\u002B'),前提是字符串長度大於1。
由字符串表示的值超過無符號整型的最大值2的32次方-1。

Parameters:
s - the String containing the unsigned integer representation to be parsed
s -包含要被轉換的無符號整數的字符串

radix - the radix to be used while parsing s.
radix - 轉換s時使用的進制數。

Returns:
the integer represented by the string argument in the specified radix.
指定進制參數表示的整數。
Throws:
NumberFormatException - if the String does not contain a parsable int.
NumberFormatException - 如果字符串不包含可解析的int。

Since:
1.8

parseUnsignedInt

public static int parseUnsignedInt(String s) throws NumberFormatException
Parses the string argument as an unsigned decimal integer. The characters in the string must all be decimal digits, except that the first character may be an an ASCII plus sign ‘+’ ('\u002B'). The resulting integer value is returned, exactly as if the argument and the radix 10 were given as arguments to the parseUnsignedInt(java.lang.String, int) method.
將字符串參數轉換爲十進制無符號整數。字符串中的字符必須全部是十進制數的數字,除了第一個字符可能是表示表示正值的ASCII加號’+’('\u002B')。返回所得到的整數值,就像parseUnsignedInt(s, 10)方法一樣。

Parameters:
s - a String containing the unsigned int representation to be parsed
s -包含要被轉換的無符號整數的字符串

Returns:
the unsigned integer value represented by the argument in decimal.
十進制參數表示的整數。

Throws:
NumberFormatException - if the string does not contain a parsable unsigned integer.
NumberFormatException - 如果字符串不包含可解析的無符號整數。

Since:
1.8

valueOf

public static Integer valueOf(String s, int radix) throws NumberFormatException
Returns an Integer object holding the value extracted from the specified String when parsed with the radix given by the second argument. The first argument is interpreted as representing a signed integer in the radix specified by the second argument, exactly as if the arguments were given to the parseInt(java.lang.String, int) method. The result is an Integer object that represents the integer value specified by the string.
返回一個Integer對象,保存從指定的String解析得來的值,第二個參數表示進制數。第一個參數被解釋爲以第二個參數指定進制數表示一個有符號整數,就像parseInt(java.lang.String, int)方法一樣。結果是一個Integer對象,表示由字符串指定的整數值。

In other words, this method returns an Integer object equal to the value of:
也就是說,該方法返回一個Integer對象的值等於:

new Integer(Integer.parseInt(s, radix))

Parameters:
s - the string to be parsed.
s - 要解析的字符串。

radix - the radix to be used in interpreting s
radix - 用於解釋s的進制數

Returns:
an Integer object holding the value represented by the string argument in the specified radix.
一個Integer對象,保存由字符串參數表示的值,以指定進制數。

Throws:
NumberFormatException - if the String does not contain a parsable int.
NumberFormatException - 如果字符串不包含可解析的無符號整數。

valueOf

public static Integer valueOf(String s) throws NumberFormatException
Returns an Integer object holding the value of the specified String. The argument is interpreted as representing a signed decimal integer, exactly as if the argument were given to the parseInt(java.lang.String) method. The result is an Integer object that represents the integer value specified by the string.
返回一個Integer對象,保存從指定的String解析得來的值。參數被解釋爲表示一個十進制有符號整數,就像parseInt(java.lang.String)方法一樣。結果是一個Integer對象,表示由字符串指定的整數值。

In other words, this method returns an Integer object equal to the value of:
也就是說,該方法返回一個Integer對象的值等於:

new Integer(Integer.parseInt(s))

Parameters:
s - the string to be parsed.
s - 要解析的字符串。

Returns:
an Integer object holding the value represented by the string argument.
一個Integer對象,保存由字符串參數表示的值。

Throws:
NumberFormatException - if the string cannot be parsed as an integer.
NumberFormatException - 如果字符串不包含可解析的無符號整數。

valueOf

public static Integer valueOf(int i)
Returns an Integer instance representing the specified int value. If a new Integer instance is not required, this method should generally be used in preference to the constructor Integer(int), as this method is likely to yield significantly better space and time performance by caching frequently requested values. This method will always cache values in the range -128 to 127, inclusive, and may cache other values outside of this range.
返回一個表示指定int值的Integer實例。如果不需要新的Integer實例,則該方法通常優先於構造函數Integer(int),因爲該方法通過緩存常用的值從而產生明顯更好的空間和時間性能。此方法總是緩存-128到127內的值,並可能緩存超出此範圍之外的其他值。

Parameters:
i - an int value.
i - 一個int值。

Returns:
an Integer instance representing i.
表示i的一個Integer實例。

Since:
1.5

byteValue

public byte byteValue()
Returns the value of this Integer as a byte after a narrowing primitive conversion.
經過縮窄原始轉換後,返回該Integer的值爲byte。

Overrides:
byteValue in class Number

Returns:
the numeric value represented by this object after conversion to type byte.
在轉換爲byte之後,該對象表示的數字值。

See The Java Language Specification:
5.1.3 Narrowing Primitive Conversions

shortValue

public short shortValue()
Returns the value of this Integer as a short after a narrowing primitive conversion.
經過縮窄原始轉換後,返回該Integer的值爲short。

Overrides:
shortValue in class Number

Returns:
the numeric value represented by this object after conversion to type short.
在轉換爲short之後,該對象表示的數字值。

See The Java Language Specification:
5.1.3 Narrowing Primitive Conversions

intValue

public int intValue()
Returns the value of this Integer as an int.
返回該Integer的值爲int。

Specified by:
intValue in class Number

Returns:
the numeric value represented by this object after conversion to type int.
在轉換爲int之後,該對象表示的數字值。

longValue

public long longValue()
Returns the value of this Integer as a long after a widening primitive conversion.
經過擴展原始轉換後,返回該Integer的值爲long。

Specified by:
longValue in class Number
Returns:
the numeric value represented by this object after conversion to type long.
在轉換爲long之後,該對象表示的數字值。

See Also:
toUnsignedLong(int)
See The Java Language Specification:
5.1.2 Widening Primitive Conversions

floatValue

public float floatValue()
Returns the value of this Integer as a float after a widening primitive conversion.
經過擴展原始轉換後,返回該Integer的值爲flaot。

Specified by:
floatValue in class Number

Returns:
the numeric value represented by this object after conversion to type float.
在轉換爲float之後,該對象表示的數字值。

See The Java Language Specification:
5.1.2 Widening Primitive Conversions

doubleValue

public double doubleValue()
Returns the value of this Integer as a double after a widening primitive conversion.
經過擴展原始轉換後,返回該Integer的值爲double。

Specified by:
doubleValue in class Number
Returns:
the numeric value represented by this object after conversion to type double.
在轉換爲double之後,該對象表示的數字值。

See The Java Language Specification:
5.1.2 Widening Primitive Conversions

toString

public String toString()
Returns a String object representing this Integer’s value. The value is converted to signed decimal representation and returned as a string, exactly as if the integer value were given as an argument to the toString(int) method.
返回一個String對象,表示此Integer的值。該值被轉換爲帶符號的十進制表示形式,並作爲字符串返回,就像toString(int)方法。

Overrides:
toString in class Object

Returns:
a string representation of the value of this object in base 10.
該對象的值的字符串表示,使用base10。

hashCode

public int hashCode()
Returns a hash code for this Integer.
返回該Integer的hash code。

Overrides:
hashCode in class Object

Returns:
a hash code value for this object, equal to the primitive int value represented by this Integer object.
該對象的hash code,等於該Integer對象的原始int值。

See Also:
Object.equals(java.lang.Object), System.identityHashCode(java.lang.Object)

hashCode

public static int hashCode(int value)
Returns a hash code for a int value; compatible with Integer.hashCode().
返回一個int值的hash code,兼容Integer.hashCode()

Parameters:
value - the value to hash
value - 要hash的值

Returns:
a hash code value for a int value.
int值的hash code

Since:
1.8

equals

public boolean equals(Object obj)
Compares this object to the specified object. The result is true if and only if the argument is not null and is an Integer object that contains the same int value as this object.
將此對象與指定對象進行比較。結果是true當且僅當該參數不是null並且是包含相同int值的Integer對象。

Overrides:
equals in class Object

Parameters:
obj - the object to compare with.
obj - 要比較的對象。

Returns:
true if the objects are the same; false otherwise.
如果對象是一樣的返回true,否則false。

See Also:
Object.hashCode(), HashMap

getInteger

public static Integer getInteger(String nm)
Determines the integer value of the system property with the specified name.
獲取具有指定名稱的系統屬性的整數值。

The first argument is treated as the name of a system property. System properties are accessible through the System.getProperty(java.lang.String) method. The string value of this property is then interpreted as an integer value using the grammar supported by decode and an Integer object representing this value is returned.
參數被視爲系統屬性的名稱。系統屬性可通過System.getProperty(java.lang.String)方法訪問。此屬性的字符串值被解釋爲一個整數值,使用decode支持的語法,返回表示該值的Integer對象。

If there is no property with the specified name, if the specified name is empty or null, or if the property does not have the correct numeric format, then null is returned.
如果沒有指定名稱的屬性,或者指定的名稱爲空或null,或者該屬性沒有正確的數字格式,則返回null。

In other words, this method returns an Integer object equal to the value of:
換句話說,此方法返回一個Integer對象的值等於:

getInteger(nm, null)

Parameters:
nm - property name.
nm - 屬性名稱。

Returns:
the Integer value of the property.
屬性的Integer值。

Throws:
SecurityException - for the same reasons as System.getProperty
SecurityException - 原因與System.getProperty相同

See Also:
System.getProperty(java.lang.String), System.getProperty(java.lang.String, java.lang.String)

getInteger

public static Integer getInteger(String nm, int val)
Determines the integer value of the system property with the specified name.
獲取具有指定名稱的系統屬性的整數值。

The first argument is treated as the name of a system property. System properties are accessible through the System.getProperty(java.lang.String) method. The string value of this property is then interpreted as an integer value using the grammar supported by decode and an Integer object representing this value is returned.
第一個參數被視爲系統屬性的名稱。系統屬性可通過System.getProperty(java.lang.String)方法訪問。此屬性的字符串值被解釋爲一個整數值,使用decode支持的語法,返回表示該值的Integer對象。

The second argument is the default value. An Integer object that represents the value of the second argument is returned if there is no property of the specified name, if the property does not have the correct numeric format, or if the specified name is empty or null.
第二是參數是默認值。如果沒有指定名稱的屬性,或者指定的名稱爲空或null,或者該屬性沒有正確的數字格式,則返回表示第二個參數的一個Integer對象。

In other words, this method returns an Integer object equal to the value of:
換句話說,此方法返回一個Integer對象的值等於:

getInteger(nm, new Integer(val))

but in practice it may be implemented in a manner such as:
但實際上可以以下列方式實現:

 Integer result = getInteger(nm, null);
 return (result == null) ? new Integer(val) : result;

to avoid the unnecessary allocation of an Integer object when the default value is not needed.
以避免在不需要默認值時不必要地分配一個Integer對象。

Parameters:
nm - property name.
nm - 屬性名稱。
val - default value.
val - 默認值。

Returns:
the Integer value of the property.
屬性的Integer值。

Throws:
SecurityException - for the same reasons as System.getProperty
SecurityException - 原因與System.getProperty相同

See Also:
System.getProperty(java.lang.String), System.getProperty(java.lang.String, java.lang.String)

getInteger

public static Integer getInteger(String nm, Integer val)
Returns the integer value of the system property with the specified name. The first argument is treated as the name of a system property. System properties are accessible through the System.getProperty(java.lang.String) method. The string value of this property is then interpreted as an integer value, as per the decode method, and an Integer object representing this value is returned; in summary:
If the property value begins with the two ASCII characters 0x or the ASCII character #, not followed by a minus sign, then the rest of it is parsed as a hexadecimal integer exactly as by the method valueOf(java.lang.String, int) with radix 16.
If the property value begins with the ASCII character 0 followed by another character, it is parsed as an octal integer exactly as by the method valueOf(java.lang.String, int) with radix 8.
Otherwise, the property value is parsed as a decimal integer exactly as by the method valueOf(java.lang.String, int) with radix 10.
The second argument is the default value. The default value is returned if there is no property of the specified name, if the property does not have the correct numeric format, or if the specified name is empty or null.
獲取具有指定名稱的系統屬性的整數值。第一個參數被視爲系統屬性的名稱。系統屬性可通過System.getProperty(java.lang.String)方法訪問。此屬性的字符串值被解釋爲一個整數值,按照decode方法,返回表示該值的Integer對象。綜上所述:
如果屬性值以兩個ASCII字符0x或ASCII字符#開頭,後面沒有跟減號,則它的其餘部分將轉換爲十六進制整數,就像valueOf(java.lang.String, int),int傳進制數16。
如果屬性值以ASCII字符0開頭,後面跟另一個字符,則將其解析爲八進制整數,就像valueOf(java.lang.String, int),int傳進制數8。
否則,屬性值將被解析爲十進制整數,就像valueOf(java.lang.String, int),int傳進制數10。
第二是參數是默認值。如果沒有指定名稱的屬性,或者指定的名稱爲空或null,或者該屬性沒有正確的數字格式,則返回表示第二個參數的一個Integer對象。

Parameters:
nm - property name.
nm - 屬性值。
val - default value.
val - 默認值。

Returns:
the Integer value of the property.
屬性的 Integer值。

Throws:
SecurityException - for the same reasons as System.getProperty
SecurityException - 原因與System.getProperty相同

See Also:
System.getProperty(java.lang.String), System.getProperty(java.lang.String, java.lang.String)

decode

public static Integer decode(String nm) throws NumberFormatException
Decodes a String into an Integer. Accepts decimal, hexadecimal, and octal numbers given by the following grammar:
將一個String解碼爲一個Integer。接受十進制,十六進制和八進制數,語法如下:

DecodableString:
Signopt DecimalNumeral
Signopt 0x HexDigits
Signopt 0X HexDigits
Signopt # HexDigits
Signopt 0 OctalDigits

Sign:

+

DecimalNumeral, HexDigits, and OctalDigits are as defined in section 3.10.1 of The Java Language Specification, except that underscores are not accepted between digits.
DecimalNumeral,HexDigits,和OctalDigits如在The Java Language Specification 3.10.1部分所定義,所不同的數字之間不接受下劃線。

The sequence of characters following an optional sign and/or radix specifier ("0x", "0X", "#", or leading zero) is parsed as by the Integer.parseInt method with the indicated radix (10, 16, or 8). This sequence of characters must represent a positive value or a NumberFormatException will be thrown. The result is negated if first character of the specified String is the minus sign. No whitespace characters are permitted in the String.
可選符號和/或進制數描述符("0x", "0X", "#", 或前導零)之後的字符序列按照指定進制數(10,16或8)的Integer.parseInt方法進行解析。這個字符序列必須表示一個正值否則NumberFormatException將被拋出。如果指定字符串的第一個字符是減號則結果是負的。在String中不允許有空格字符。

Parameters:
nm - the String to decode.
nm - 要decode的字符串。

Returns:
an Integer object holding the int value represented by nm
一個Integer對象,保存nm表示的int值。

Throws:
NumberFormatException - if the String does not contain a parsable integer.
NumberFormatException - 如果字符串不包含可轉換的整數。

See Also:
parseInt(java.lang.String, int)

compareTo

public int compareTo(Integer anotherInteger)
Compares two Integer objects numerically.
在數值上比較兩個Integer對象。

Specified by:
compareTo in interface Comparable

Parameters:
anotherInteger - the Integer to be compared.
anotherInteger - 要比較的Integer。

Returns:
the value 0 if this Integer is equal to the argument Integer; a value less than 0 if this Integer is numerically less than the argument Integer; and a value greater than 0 if this Integer is numerically greater than the argument Integer (signed comparison).
如果該Integer等於參數Integer,則返回0;如果該Integer數值上小於參數Integer,則返回一個小於0的值;如果該Integer數值上大於參數Integer,則返回一個大於0的值。

Since:
1.2

compare

public static int compare(int x, int y)
Compares two int values numerically. The value returned is identical to what would be returned by:
數值上比較兩個int值。返回的值與以下返回值相同:

`Integer.valueOf(x).compareTo(Integer.valueOf(y))`

Parameters:
x - the first int to compare
x - 第一個要比較的int
y - the second int to compare
y - 第二個要比較的int

Returns:
the value 0 if x == y; a value less than 0 if x < y; and a value greater than 0 if x > y
如果x == y,返回0,如果x < y,返回一個負值;如果x > y,返回一個正值。
Since:
1.7

compareUnsigned

public static int compareUnsigned(int x, int y)
Compares two int values numerically treating the values as unsigned.
數值上比較兩個無符號int值。

Parameters:
x - the first int to compare
x - 第一個要比較的int
y - the second int to compare
y - 第二個要比較的int

Returns:
the value 0 if x == y; a value less than 0 if x < y as unsigned values; and a value greater than 0 if x > y as unsigned values
如果x == y,返回0;作爲無符號的值,如果x < y,返回一個負值;作爲無符號的值,如果x > y,返回一個正值。

Since:
1.8

toUnsignedLong

public static long toUnsignedLong(int x)
Converts the argument to a long by an unsigned conversion. In an unsigned conversion to a long, the high-order 32 bits of the long are zero and the low-order 32 bits are equal to the bits of the integer argument. Consequently, zero and positive int values are mapped to a numerically equal long value and negative int values are mapped to a long value equal to the input plus 232.
參數無符號轉換爲long。在無符號轉換爲long時,long的高32位是零,低32位等於整數參數的位。因此,零和正的int值映射到數值上相等的long,而負的int值映射到參數加上2的32次方的long值。

Parameters:
x - the value to convert to an unsigned long
x - 要轉換爲無符號long的值

Returns:
the argument converted to long by an unsigned conversion
參數無符號轉換以後的long

Since:
1.8

divideUnsigned

public static int divideUnsigned(int dividend, int divisor)
Returns the unsigned quotient of dividing the first argument by the second where each argument and the result is interpreted as an unsigned value.
返回第一個參數除以第二個參數的的無符號商,其中每個參數和結果都是無符號值。

Note that in two’s complement arithmetic, the three other basic arithmetic operations of add, subtract, and multiply are bit-wise identical if the two operands are regarded as both being signed or both being unsigned. Therefore separate addUnsigned, etc. methods are not provided.
注意,在二進制補碼算法中,如果兩個操作數都被當做有符號的或者兩個都是無符號的,則加法,減法和乘法這三個其他基本算術運算是位同的。因此不提供addUnsigned等方法。

Parameters:
dividend - the value to be divided
dividend - 被除數
divisor - the value doing the dividing
divisor - 除數

Returns:
the unsigned quotient of the first argument divided by the second argument
第一個參數除以第二個參數的的無符號商

Since:
1.8
See Also:
remainderUnsigned(int, int)

remainderUnsigned

public static int remainderUnsigned(int dividend, int divisor)
Returns the unsigned remainder from dividing the first argument by the second where each argument and the result is interpreted as an unsigned value.
返回第一個參數除以第二個參數的的無符號餘數,其中每個參數和結果都是無符號值。

Parameters:
dividend - the value to be divided
dividend - 被除數
divisor - the value doing the dividing
divisor - 除數

Returns:
the unsigned remainder of the first argument divided by the second argument
第一個參數除以第二個參數的的無符號餘數

Since:
1.8
See Also:
divideUnsigned(int, int)

highestOneBit

public static int highestOneBit(int i)
Returns an int value with at most a single one-bit, in the position of the highest-order (“leftmost”) one-bit in the specified int value. Returns zero if the specified value has no one-bits in its two’s complement binary representation, that is, if it is equal to zero.
返回一個只有一個bit的int值,指定int值的最高(“最左”)的1位。如果指定的值在其二進制補碼二進制表示中沒有1位,也就是說,如果它等於零,則返回零。

Parameters:
i - the value whose highest one bit is to be computed
i - 要計算最高一位的值。

Returns:
an int value with a single one-bit, in the position of the highest-order one-bit in the specified value, or zero if the specified value is itself equal to zero.
一個只有1位的int值,是指定int值的最高的1位,如果指定值本身等於零,則爲零。

Since:
1.5

lowestOneBit

public static int lowestOneBit(int i)
Returns an int value with at most a single one-bit, in the position of the lowest-order (“rightmost”) one-bit in the specified int value. Returns zero if the specified value has no one-bits in its two’s complement binary representation, that is, if it is equal to zero.
返回一個只有一個bit的int值,指定int值的最低(“最右”)的1位。如果指定的值在其二進制補碼二進制表示中沒有1位,也就是說,如果它等於零,則返回零。

Parameters:
i - the value whose lowest one bit is to be computed
i - 要計算最低一位的值。

Returns:
an int value with a single one-bit, in the position of the lowest-order one-bit in the specified value, or zero if the specified value is itself equal to zero.
一個只有1位的int值,是指定int值的最低的1位,如果指定值本身等於零,則爲零。

Since:
1.5

numberOfLeadingZeros

public static int numberOfLeadingZeros(int i)
Returns the number of zero bits preceding the highest-order (“leftmost”) one-bit in the two’s complement binary representation of the specified int value. Returns 32 if the specified value has no one-bits in its two’s complement representation, in other words if it is equal to zero.
返回指定的值在其二進制補碼二進制表示的最高(“最左”)的1位之前的0的個數。如果指定值中沒有1位,也就是說,如果它等於零,則返回32。

Note that this method is closely related to the logarithm base 2. For all positive int values x:
注意,該方法與對數base2密切相關。對所有正的int值x:

floor(log2(x)) = 31 - numberOfLeadingZeros(x)
ceil(log2(x)) = 32 - numberOfLeadingZeros(x - 1)

Parameters:
i - the value whose number of leading zeros is to be computed
i - 要計算前導零數的值

Returns:
the number of zero bits preceding the highest-order (“leftmost”) one-bit in the two’s complement binary representation of the specified int value, or 32 if the value is equal to zero.
返回指定的值在其二進制補碼二進制表示的最高(“最左”)的1位之前的0的個數。如果指定值中沒有1位,也就是說,如果它等於零,則返回32。

Since:
1.5

numberOfTrailingZeros

public static int numberOfTrailingZeros(int i)
Returns the number of zero bits following the lowest-order (“rightmost”) one-bit in the two’s complement binary representation of the specified int value. Returns 32 if the specified value has no one-bits in its two’s complement representation, in other words if it is equal to zero.
返回指定的值在其二進制補碼二進制表示的最低(“最右”)的1位之後的0的個數。如果指定值中沒有1位,也就是說,如果它等於零,則返回32。

Parameters:
i - the value whose number of trailing zeros is to be computed
i - 要計算後置零數的值

Returns:
the number of zero bits following the lowest-order (“rightmost”) one-bit in the two’s complement binary representation of the specified int value, or 32 if the value is equal to zero.
返回指定的值在其二進制補碼二進制表示的最低(“最右”)的1位之後的0的個數。如果指定值中沒有1位,也就是說,如果它等於零,則返回32。

Since:
1.5

bitCount

public static int bitCount(int i)
Returns the number of one-bits in the two’s complement binary representation of the specified int value. This function is sometimes referred to as the population count.
返回指定的int值的二進制補碼二進制表示中的1位的個數。此方法有時稱爲人口數量。

Parameters:
i - the value whose bits are to be counted
i - 要計算bit數的值

Returns:
the number of one-bits in the two’s complement binary representation of the specified int value.
指定的值在其二進制補碼二進制表示的最低(“最右”)的1位之後的0的個數。

Since:
1.5

rotateLeft

public static int rotateLeft(int i, int distance)
Returns the value obtained by rotating the two’s complement binary representation of the specified int value left by the specified number of bits. (Bits shifted out of the left hand, or high-order, side reenter on the right, or low-order.)
返回將指定的int值的二進制補碼二進制表示往左旋轉指定位數所得到的int值。(移位超過最左或最高的,從最右或最低重新進入)。

Note that left rotation with a negative distance is equivalent to right rotation:
注意,具有負距離的左旋相當於右旋:
rotateLeft(val, -distance) == rotateRight(val, distance)
Note also that rotation by any multiple of 32 is a no-op, so all but the last five bits of the rotation distance can be ignored, even if the distance is negative:
還要注意,32的任意倍數的旋轉是不變的,所以除了旋轉距離的最後五位之外都可以忽略,即便距離爲負值:
rotateLeft(val, distance) == rotateLeft(val, distance & 0x1F)

Parameters:
i - the value whose bits are to be rotated left
i - 要左旋的值
distance - the number of bit positions to rotate left
distance - 左旋的距離

Returns:
the value obtained by rotating the two’s complement binary representation of the specified int value left by the specified number of bits.
將指定的int值的二進制補碼二進制表示往左旋轉指定位數所得到的int值。

Since:
1.5

rotateRight

public static int rotateRight(int i, int distance)
Returns the value obtained by rotating the two’s complement binary representation of the specified int value right by the specified number of bits. (Bits shifted out of the right hand, or low-order, side reenter on the left, or high-order.)
返回將指定的int值的二進制補碼二進制表示往右旋轉指定位數所得到的int值。(移位超過最右或最低的,從最左或最高重新進入)。

Note that right rotation with a negative distance is equivalent to left rotation:
注意,具有負距離的右旋相當於左旋:
rotateRight(val, -distance) == rotateLeft(val, distance)
Note also that rotation by any multiple of 32 is a no-op, so all but the last five bits of the rotation distance can be ignored, even if the distance is negative:
還要注意,32的任意倍數的旋轉是不變的,所以除了旋轉距離的最後五位之外都可以忽略,即便距離爲負值:
rotateRight(val, distance) == rotateRight(val, distance & 0x1F)

Parameters:
i - the value whose bits are to be rotated right
i - 要右旋的值
distance - the number of bit positions to rotate right
distance - 右旋的距離

Returns:
the value obtained by rotating the two’s complement binary representation of the specified int value right by the specified number of bits.
將指定的int值的二進制補碼二進制表示往右旋轉指定位數所得到的int值。

Since:
1.5

reverse

public static int reverse(int i)
Returns the value obtained by reversing the order of the bits in the two’s complement binary representation of the specified int value.
返回將指定的int值的二進制補碼二進制表示進行位反轉所得到的int值。

Parameters:
i - the value to be reversed
i - 要反轉的值

Returns:
the value obtained by reversing order of the bits in the specified int value.
將指定的int值的二進制補碼二進制表示進行位反轉所得到的int值。

Since:
1.5

signum

public static int signum(int i)
Returns the signum function of the specified int value. (The return value is -1 if the specified value is negative; 0 if the specified value is zero; and 1 if the specified value is positive.)
返回指定的int值的正負號。(如果指定的值爲負,返回值爲-1;如果指定的值爲零,返回值爲0;如果指定的值爲正,返回值爲1)。

Parameters:
i - the value whose signum is to be computed
i - 要計算正負號的值

Returns:
the signum function of the specified int value.
指定int值的正負號

Since:
1.5

reverseBytes

public static int reverseBytes(int i)
Returns the value obtained by reversing the order of the bytes in the two’s complement representation of the specified int value.
返回將指定的int值的二進制補碼二進制表示進行byte反轉所得到的int值。

Parameters:
i - the value whose bytes are to be reversed
i - 要byte反轉的值

Returns:
the value obtained by reversing the bytes in the specified int value.
將指定的int值的二進制補碼二進制表示進行byte反轉所得到的int值。

Since:
1.5

sum

`public static int sum(int a, int b)
Adds two integers together as per the + operator.
像+運算符那樣將兩個整數相加。

Parameters:
a - the first operand
a - 第一個操作數
b - the second operand
b - 第二個操作數

Returns:
the sum of a and b
a和b的和

Since:
1.8
See Also:
BinaryOperator

max

public static int max(int a, int b)
Returns the greater of two int values as if by calling Math.max.
返回兩個int值的大者,就像調用Math.max

Parameters:
a - the first operand
a - 第一個操作數
b - the second operand
b - 第二個操作數

Returns:
the greater of a and b
a和b的大者

Since:
1.8
See Also:
BinaryOperator

min

public static int min(int a, int b)
Returns the smaller of two int values as if by calling Math.min.
返回兩個int值的小者,就像調用Math.min

Parameters:
a - the first operand
a - 第一個操作數
b - the second operand
b - 第二個操作數

Returns:
the smaller of a and b
a和b的小者

Since:
1.8
See Also:
BinaryOperator

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章