Integer Flashcards
Constructor
- Integer(int value)
- Integer(String s)
compare/compareTo
- compare(int x, int y)
Compares two int values numerically. The value returned is identical to what would be returned by:
Integer.valueOf(x).compareTo(Integer.valueOf(y))
- compareTo(Integer anotherInteger)
Compares two Integer objects numerically.
equals and toString()
- 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.
- String toString(int i)
Returns a String object representing the specified integer (in this case, i)
- String toString()
Returns a String object representing this Integer’s value.
longValue()/floatValue()/doubleValue()/shortValue()/byteValue()
- Returns the value of this Integer as a long/float/double/short/byte/int value
valueOf(int i/String s)
- valueOf(String s)
- 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.
- 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
parseInt() and parseInt(String s)
- int parseInt(String s) throws NumberFormatException
Parses the string argument as a signed decimal integer.
- int parseInt(String s, int radix) throws NumberFormatException
Parses the string argument as a signed integer in the radix specified by the second argument.
highestOneBit(int i)
- 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.
lowestOneBit(int i)
- 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.
bitCount(int i)
- 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.
numberOfLeadingZeros(int i)
- 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.
numberOfTrailingZeros(int i)
- 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.
toBinaryString(int i)
- toBinaryString(int i)
Returns a string representation of the integer argument as an unsigned integer in base 2.