In our previous video we have seen that how Super keyword at Constructor level works with example. Now in this video we are going to learn about what are Object Wrapper Class in Java provided with suitable example.
A Object Wrapper Class in Java wraps around a data type and gives it an object appearance. The data type is required as an object, this object can be used.
Object Wrapper class in Java programming include methods to unwrap the object and give back the data type. Wrapper class in Java provides a mechanism to convert primitive into object and object into primitive.
There are many to uses with Object Wrapper class in Java language. They are :
1. To convert simple data types into objects, that is, to give object form to a data type; here constructors are used.
2. To convert strings into data types (known as parsing operations), here methods of type parseXXX() are used.
Autoboxing and unboxing feature converts primitive into object and object into primitive automatically. The automatic conversion of primitive into object is known as autoboxing and vice-versa unboxing in Java.
One of the eight classes of java.lang package are known as Wrapper class.
Primitive : boolean, Wrapper : Boolean
Primitive : char, Wrapper : Character
Primitive : byte, Wrapper : Byte
Primitive : short, Wrapper : Short
Primitive : int, Wrapper : Integer
Primitive : long, Wrapper : Long
public class Wrapper
public static void main (String args )
Integer i=Integer.valueof (a); //converting int into Integer
Integer j=a; //autoboxing, now compiler will write Integer.valueof (a) internally
System.out.println (a+" "+i+" "+j);
20 20 20
Now we will see an example for Wrapper to primitive in Java.
public class Wrapper1
public static void main(String args)
Integer a=new Integer(3);
int i=a.intValue();//converting Integer to int int j=a;
System.out.println(a+" "+i+" "+j);
So, this was Object Wrapper class in Java programming language. In our next video, we will see what are StringBuffer and StringBuilder Classes in Java language.
Have a friend to whom you would want to share this course?