Java Integer class

tutorial and example
tutorial and example

The Integer class wraps a primitive int type value in an object. Its object contains only a single field whose type is int.

Methods:

The java.lang.Integer class provides several different methods for converting an Integer to a String or vice versa. This class also provides other constants and methods which are useful when we are dealing with int.

Methods Description
bitCount() It returns the number of one bits in two’s complement binary representation of the given int value.
byteintValue() It returns the value of Integer as a byte.
compare() It compares the two int values.
compareTo() It compares two Integer objects numerically.
compareUnsigned() It compares the two int values keeping the values unsigned.
decode() It decodes a string into an Integer.
divideUnsigned() It returns the unsigned quotient by dividing the first argument by the second.
doubleValue() IT returns the value of Integer as a double.
equals() It compares this object with the specified object.
floatValue() It returns the float type value for the given Integer object.
getInteger() It determines the int value of the system property for the specified name.
hashCode() It returns the hash code for the specified Integer object.
highestOneBit() It returns an int value with at most one single bit in the place of the highest order one-bit.
intValue() It returns an int value for this Integer.
longValue() It returns a long value for this Integer object
lowestOneBit() It returns an int value with at most one single bit in the place of the lowest order one-bit.
max() It returns the greater of the two int values.
min() It returns the smaller of the two int values.
numberOfLeadingZeros(int i) It returns the total number of zero bytes following the highest order one-bit in the two’s complement binary representation.
numberOfTrailingZeroes(int i) It returns the total number of zero bytes following the lowest order one-bit in the two’s complement binary representation.
parseInt() It parses the CharSequence or String argument as a specified signed int.
parseUnsignedInteger() It parses the given CharSequence or String argument as an unsigned int.
remainderUnsigned() It returns the unsigned remainder by dividing the first argument with the second argument.
reverse() It returns the value obtained by the reversing the given order of bits in 2’s complement binary representation.
reverseBytes() It returns the value obtained by the reversing the given order of bytes in 2’s complement representation.
rotateLeft() It returns the value obtained by rotating the 2’s complement binary representation of the given int value by left and by the specified number of bits.
rotateRight() It returns the value obtained by rotating the 2’s complement binary representation of the given int value by right and by the specified number of bits.
shortValue() It returns the short type value for the given Integer object.
signum() It returns the signum function for the given int value.
sum() It adds the two specified int values and returns the same result as the + operator.
toBinaryString() It returns the string representation for the given integer argument as an unsigned argument with base 2.
toHexString() It returns the string representation for the given int argument as an unsigned argument with base 16.
toOctalString() Returns the string representation for the given int argument as an unsigned argument with base 8.
toString() It returns the string which represents the same value as of the given integer.
toUnsignedString() It returns the string representation for the argument as an unsigned decimal value.
toUnsignedLong() It converts the given int argument to long by an unsigned conversion.
valueOf() It returns an int instance which represents the specified value.

Examples-

Example:1

Output:

Example:2

Output: