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

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值