Core Java - [Wrapper Class]

♠ Posted by Unknown in at 01:29

Wrapper Class


The vectors cannot handle primitive data types like int, float, long, char,  and double. Primitive data types may be converted into object types by using the wrapper classes contained in the java.lang package. Below table shows the simple data types and their corresponding wrapper class types.

Simple Type

Wrapper Class

boolean

Boolean

char

Character

double

Double

float

Float

int

Integer

long

Long



Converting Primitive to Objects Using Constructor
Converting Objects to Primitive using method
Converting Numbers to Strings
Converting String objects to Numeric objects
Converting Numeric Strings to Primitive Numbers
Integer IntVal = new Integer()
int i =  IntVal.intValue()
str = Integer.toString(i)
IntVal = Integer.valueOf()
int i = Integer.parseInt(str)
Float FloatVal = new Float()
float f = FloatVal.floatValue()
str = Float.toString(f)
FloatVal = Float.valueOf()
long l = Long.parseLong(str)
Double DoubleVal = new Double()
double d =  DoubleVal.doubleValue()
str = Double.toString(d)
DoubleVal = Double.valueOf()

Long LongVal = new Long()
long l = LongVal.longValue()
str = Long.toString(l)
LongVal = Long.valueOf()



The Wrapper classes have number of methods for handling primitive data types and objects.

0 comments:

Post a Comment