TYPE WRAPPERS or WRAPPER CLASSES
A Wrapper class is a class in Java’s class library that represents the
characteristics and behaviour of a primitive data type.
There is a wrapper class for each primitive data type
Wrapper classes are members of the package java.lang
Data Type Wrapper class
byte Byte
short Short
int Integer
long Long
float Float
double Double
boolean Boolean
char Character
Functions of class Integer
1) static int parseInt(String s)
Converts a String that contains digits (and optionally a sign)to
primitive data type int.
e.g. : int n =Integer.parseInt(“174”); //n=174
Functions of class Long
1) static long parseLong(String s)
Converts a String that contains digits (and optionally a sign)to
primitive data type long.
e.g. : long n =Long.parseLong(“-12345”); //n=-12345
Functions of class Float
1) static float parseFloat(String s)
Converts a String that represents a real numeric constant to primitive
data type float.
e.g. : float f =Float.parseFloat(“5.67”); //f=5.67F
Functions of class Double
1) static double parseDouble(String s)
Converts a String that represents a real numeric constant to primitive
data type double.
e.g. : double d =Double.parseDouble(“12.785”); //d=12.785
Functions of Character wrapper class
1) static boolean isDigit(char ch)
Determines if the specified character is a digit.
2) static boolean isLetter(char ch)
Determines if the specified character is a letter.
3) static boolean isLetterOrDigit(char ch)
Determines if the specified character is a letter or digit.
4) static boolean isLowerCase(char ch)
Determines if the specified character is a lowercase character.
5) static boolean isUpperCase(char ch)
Determines if the specified character is an uppercase character.
6) static boolean isWhitespace(char ch)
Determines if the specified character is white space according to
Java.
7) static char toLowerCase(char ch)
Converts the character argument to lowercase.
8) static char toUpperCase(char ch)
Converts the character argument to uppercase.
Example:
boolean b=Character.isUpperCase(ch);
if(b==true)//if(Character.isUpperCase(ch))
{
Sytem.out.println(“Capital letter”);
}
Boxing / Autoboxing
Automatic conversion of primitive types to the object of their corresponding
wrapper classes is known as autoboxing. For example – conversion of int to
Integer, long to Long, double to Double etc.
e.g. : int n=10;
Integer obj=n;//example of autoboxing
Unboxing
It is just the reverse process of autoboxing. Automatically converting an object of
a wrapper class to its corresponding primitive type is known as unboxing. For
example – conversion of Integer to int, Long to long, Double to double etc.
e.g. : Integer obj=new Integer(25);
int n=obj;//example of unboxing