|
|
| Lang
Package - Wrapper Class |
|
Home | Lang Basics |
String | StringBuffer |
Thread |
Wrapper Class | String Tokenizer
|
|
Wrapper Class:
Wrapper is nothing but, Interface between primitive data types and Address mode. Its called Wrapper Class.
Wrapper classes are classes that allow primitive types to be accessed as objects. Wrapper class is wrapper around a primitive data type.
Following table lists the primitive types and the corresponding wrapper classes:
|
| Primitive |
Wrapper |
| Boolean |
java.lang.Boolean |
| Byte |
java.lang.Byte |
| Char |
java.lang.Character |
| double |
java.lang.Double |
| Float |
java.lang.Float |
| Int |
java.lang.Integer |
| Long |
java.lang.Long |
| Short |
java.lang.Short |
| Void |
java.lang.Void |
|
one for each primitive type: Boolean, Byte, Character, Double, Float, Integer, Long, and Short
Byte, Double, Float, Integer and Short extend the abstract Number class
all are public final ie cannot be extended
get around limitations of primitive types
allow objects to be created from primitive types
all the classes have two constructor forms
all, except Character, have a valueOf(String s) method which is equivalent to new Type(String s)
all have a typeValue() method which returns the value of the object as it's primitive type. These are all
abstract methods defined in Number and overridden in each class
» public byte byteValue()
» public short shortValue()
» public int intValue()
» public long longValue()
» public float floatValue()
» public double doubleValue()
all the classes override equals(), hashCode() and toString() in Object
» equals() returns true if the values of the compared objects are the same
» hashCode() returns the same hashcode for objects of the same type having the same value
» toString() returns the string representation of the objects value
getType() returns an int that defines a character's Unicode type Integer, Short, Byte and Long
all have parseType methods eg parseInt(), parseShort(), etc that take a String and parse it into the appropriate type
the Integer and Long classes also have the static methods toBinaryString(), toOctalString() and toHexString() which take an
integer value and convert it to the appropriate String representation
Float and Double:
both classes have static fields which define POSITIVE_INFINITY, NEGATIVE_INFINITY, and
and the following methods to test a value
-> public boolean isNan()
-> public static boolean isNaN(type value)
-> public boolean isInfinite()
-> public static boolean isInfinite(type value)
Float also has a constructor that takes a double value
both classes have methods to convert a value into a bit pattern or vice versa
-> public static int floatToIntBits(float value)
-> public static float intBitsToFloat(int bits)
-> public static long doubleToLongBits(double value)
-> public static double longBitsToDouble(long bits)
|
| Back to top |
|