0% completed
In Java, wrapper classes provide a way to use primitive data types (int
, char
, double
, etc.) as objects. Each primitive type has a corresponding wrapper class in the java.lang
package:
Primitive Type | Wrapper Class |
---|---|
boolean | Boolean |
byte | Byte |
char | Character |
short | Short |
int | Integer |
long | Long |
float | Float |
double | Double |
ArrayList<Integer>
).MAX_VALUE
and MIN_VALUE
.Method | Description |
---|---|
parseBoolean(String s) | Parses the string argument as a boolean. |
valueOf(boolean b) | Returns a Boolean instance representing the specified boolean value. |
booleanValue() | Returns the value of this Boolean object as a primitive boolean. |
compare(boolean a, boolean b) | Compares two boolean values. |
toString(boolean b) | Returns a String object representing the specified boolean. |
Method | Description |
---|---|
parseByte(String s) | Parses the string argument as a signed decimal byte. |
valueOf(byte b) | Returns a Byte instance representing the specified byte value. |
byteValue() | Returns the value of this Byte as a primitive byte. |
compare(byte a, byte b) | Compares two byte values. |
toString(byte b) | Returns a String object representing the specified byte. |
Method | Description |
---|---|
isLetter(char ch) | Determines if the specified character is a letter. |
isDigit(char ch) | Determines if the specified character is a digit. |
toUpperCase(char ch) | Converts the character to uppercase. |
toLowerCase(char ch) | Converts the character to lowercase. |
valueOf(char c) | Returns a Character instance representing the specified char value. |
Method | Description |
---|---|
parseShort(String s) | Parses the string argument as a signed decimal short. |
valueOf(short s) | Returns a Short instance representing the specified short value. |
shortValue() | Returns the value of this Short as a primitive short. |
compare(short a, short b) | Compares two short values. |
toString(short s) | Returns a String object representing the specified short. |
Method | Description |
---|---|
parseInt(String s) | Parses the string argument as a signed decimal integer. |
valueOf(int i) | Returns an Integer instance representing the specified int value. |
intValue() | Returns the value of this Integer as a primitive int. |
compare(int a, int b) | Compares two int values. |
toString(int i) | Returns a String object representing the specified int. |
MAX_VALUE | Maximum value an int can have (2147483647 ). |
MIN_VALUE | Minimum value an int can have (-2147483648 ). |
Method | Description |
---|---|
parseLong(String s) | Parses the string argument as a signed decimal long. |
valueOf(long l) | Returns a Long instance representing the specified long value. |
longValue() | Returns the value of this Long as a primitive long. |
compare(long a, long b) | Compares two long values. |
toString(long l) | Returns a String object representing the specified long. |
MAX_VALUE | Maximum value a long can have (9223372036854775807L ). |
MIN_VALUE | Minimum value a long can have (-9223372036854775808L ). |
Method | Description |
---|---|
parseFloat(String s) | Parses the string argument as a floating-point number. |
valueOf(float f) | Returns a Float instance representing the specified float value. |
floatValue() | Returns the value of this Float as a primitive float. |
compare(float a, float b) | Compares two float values. |
toString(float f) | Returns a String object representing the specified float. |
MAX_VALUE | Maximum value a float can have (3.4028235e+38f ). |
MIN_VALUE | Minimum value a float can have (1.4e-45f ). |
Method | Description |
---|---|
parseDouble(String s) | Parses the string argument as a double. |
valueOf(double d) | Returns a Double instance representing the specified double value. |
doubleValue() | Returns the value of this Double as a primitive double. |
compare(double a, double b) | Compares two double values. |
toString(double d) | Returns a String object representing the specified double. |
MAX_VALUE | Maximum value a double can have (1.7976931348623157e+308 ). |
MIN_VALUE | Minimum value a double can have (4.9e-324 ). |
Below is a comprehensive example demonstrating the usage of various wrapper classes within a single Java file using the Solution
class.
Here, we have used different wrapper classes in the above example.
Wrapper classes in Java bridge the gap between primitive types and object-oriented programming by providing object representations of primitive values. This integration allows primitives to be used seamlessly within Java's collection framework and leverages the rich set of utility methods provided by these classes for data manipulation and conversion.
.....
.....
.....