You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The wrapper classes for primitive integer types in Java are Byte, Short, Integer, and Long. These classes provide utility methods for working with their respective types and are part of the java.lang package. They also offer boxing and unboxing functionalities for converting between primitive types and objects.
Key Features of Integer Wrapper Classes
Boxing and Unboxing: Automatic conversion between primitive types and wrapper classes.
Constants: Constants like MAX_VALUE, MIN_VALUE, POSITIVE_INFINITY, etc., for each type.
Utility Methods: Methods for parsing, converting, and performing operations on numeric values.
Byte, Short, Integer, and Long Wrapper Class Operations
Arithmetic Operations
Operation
Symbol
Example
Addition
+
value + value
Subtraction
-
value - value
Multiplication
*
value * value
Division
/
value / value
Modulo
%
value % value
Relational Operations
Operation
Symbol
Example
Equal to
==
value == value
Not equal to
!=
value != value
Greater than
>
value > value
Less than
<
value < value
Greater than or equal to
>=
value >= value
Less than or equal to
<=
value <= value
Static Methods
Common Static Methods for Byte, Short, Integer, and Long
Method
Description
Example
compare(T, T)
Compares two values of the type T
Integer.compare(5, 10) → Returns -1
parse<Type>(String)
Parses a String as a primitive value of type Type
Integer.parseInt("42") → Returns 42
toString()
Converts the value to its string representation
Integer.toString(42) → Returns "42"
valueOf(String)
Returns the corresponding wrapper class instance from a string value
Integer.valueOf("42") → Returns 42
bitCount()
Returns the number of one-bits in the binary representation of the value.
Integer.bitCount(5) → Returns 2
highestOneBit()
Returns the value of the highest one-bit in the binary representation.
Integer.highestOneBit(5) → Returns 4
lowestOneBit()
Returns the value of the lowest one-bit in the binary representation.
Integer.lowestOneBit(5) → Returns 1
numberOfLeadingZeros()
Returns the number of leading zeros in the binary representation.
Integer.numberOfLeadingZeros(5) → Returns 29
numberOfTrailingZeros()
Returns the number of trailing zeros in the binary representation.
Integer.numberOfTrailingZeros(5) → Returns 0
reverse()
Reverses the bits of the number.
Integer.reverse(5) → Returns 268435456
rotateLeft()
Rotates the bits left by a specified number of positions.
Integer.rotateLeft(5, 1) → Returns 10
rotateRight()
Rotates the bits right by a specified number of positions.