Sunday, September 29, 2013

What are Wrapper Classes?

Wrapper Classes wrap the primitive data type into an Object of its Class. The following table lists the wrapper classes corresponding to each primitive type:

Primitive Data TypeWrapper Class
booleanBoolean
byteByte
shortShort
intInteger
longLong
floatFloat
doubleDouble
charCharacter
True to their name, wrapper classes, contain a member variable corresponding to the primitive data type. The value in this member variable can be extracted using a method. The name of the method is of the format <primitive_data_type_name>Value(). For example, the class Boolean contains a method booleanValue() which returns the value stored in the object. This has become simpler since the introduction of autoboxing feature in Java 5.

No comments:

Post a Comment