Wrapper Classes

Java provides wrapper classes for each of the primitive types. The wrapper classes can be used to create objects from the primitive types. These are the wrapper classes for the corresponding primitive types:

Boolean

The Boolean class wraps a value of the primitive type boolean in an object.
// Creating a Boolean object
boolean found = true;
Boolean boolObj = Boolean.valueOf ( found );

// Getting back a boolean from a Boolean
boolean aBool = boolObj.booleanValue();

Other methods:

Character

The Character class wraps a value of the primitive type char in an object.
// Creating a Character object
char ch = 'a';
Character charObj = new Character ( ch );

// Getting a char back from a Character object
char ch2 = charObj.charValue();
Other methods:

Integer

The Integer class wraps a value of the primitive type int in an object.
// Creating an Integer Object
int x = 10;
Integer xObj = new Integer ( x );

// Get the integer value from an Integer object
int z = xObj.intValue();
Other methods

Double

The Double class wraps a value of the primitive type double in an object.
// Creating a Double object
double w = 2.512;
Double dObj = new Double ( w );

// Extracting the double value from a Double object.
double v = dObj.doubleValue();
Other Methods

Vector

The Vector class implements a growable array of objects. One can access the components using an integer index. But the size of the Vector can grow or shrink. Each Vector object has a capacity and a capacityIncrement. The size of the Vector increases in units of the capacityIncrement.
// Creating a default Vector of capacity 10 and capacityIncrement 0
Vector aVec = new Vector();

// Add object at a specified position in the Vector
aVec.add ( 5, anObj );

// Add object at the end of the Vector
aVec.add ( anObj );

// Remove all the elements in the Vector
aVec.clear();

// Return an object at a specified location
Object anObj = aVec.elementAt ( 5 );

// Test if an object is in the Vector
boolean found = aVec.contains ( anObj );

// Get the index of the first occurence of an element
int x = aVec.indexOf ( anObj );

// Get the index of the last occurence of an element
int x = aVec.lastIndexOf ( anObj );

// Remove an element at a specified position
Object anObj = aVec.remove ( 5 );

// Remove the first occurence of an object
boolean done = aVec.remove ( anObj );

// Replace an element at a specified position in a Vector
Object prevObj = aVec.set ( 5, anObj );

// Get the capacity of the Vector
int capa = aVec.capacity();

// Get the number of elements in a Vector
int num = aVec.size();

// Convert a Vector to an Array
Object[] anArray = aVec.toArray();

// Get a string representation of a Vector containing the String
// representation of each element
String str = aVec.toString();