Wrapper classes provide a way to use primitive types as objects. For each primitive , we have a wrapper class such as,
int Integer
byte Byte
Integer and Byte are the wrapper classes of primitive int and byte. There are times/restrictions when you need to use the primitives as objects so wrapper classes provide a mechanism called as boxing/unboxing.
Concept can be well understood by the following example as
double d = 135.0 d;
Double doubleWrapper = new Double(d);
int integerValue = doubleWrapper.intValue();
byte byteValue = doubleWrapper.byteValue();
string stringValue = doubleWrapper.stringValue();
so this is the way , we can use wrapper class type to convert into other primitive types as well. This type of conversion is used when you need to convert a primitive type to object and use them to get other primitives as well.Though for this approach , you need to write a big code . However, the same can be achieved with the simple casting technique as code snippet can be achieved as below
double d = 135.0;
int integerValue = (int) d ;
Though double value is explicitly converted to integer value also called as downcasting.