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.
Params: i – an int value.
Returns: an Integer instance representing i.
Since: 1.5

public static Integer valueOf(int i) {  
    if (i >= IntegerCache.low && i <= IntegerCache.high)  
        return IntegerCache.cache[i + (-IntegerCache.low)];  
    return new Integer(i);  
}

toBinaryString

Returns a string representation of the integer argument1 as an unsigned integer2 in base3 2.

  • Returns a string representation:返回一个字符串表示。
  • of the integer argument:这个字符串表示的内容是整数参数。
  • as an unsigned integer:表示这个整数被视为无符号整数,意味着它不包含负数。
  • in base 2:采用二进制格式表示,即只使用 0 和 1。

The unsigned integer value is the argument plus 2^32 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.
The value of the argument can be recovered from the returned string s by calling Integer. parseUnsignedInt(s, 2).
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.

Params: i – an integer to be converted to a string.
Returns: the string representation of the unsigned integer value represented by the argument in binary (base 2).
Since: JDK1.0.2
See Also: parseUnsignedInt(String, int), toUnsignedString(int, int)

public static String toBinaryString(int i) {  
    return toUnsignedString0(i, 1);  
}

Footnotes

  1. In Java, arguments are the actual values passed to a method when it is called. These values replace the parameters defined in the method signature and are used during the execution of the method. Arguments are essential for passing data between methods and enabling dynamic behavior in programs. ↩

  2. The XDR standard defines signed integers as integer. A signed integer is a 32-bit datum=(data) that encodes an integer in the range [-2147483648 to 2147483647]. An unsigned integer is a 32-bit datum that encodes a nonnegative integer in the range [0 to 4294967295]. ↩

  3. a number on which a system of counting and expressing numbers is built up, for example 10 in the decimal system and 2 in the binary system 基数(如十进制的 10 和二进制的 2) ↩