Wrapper classes in java:
A wrapper class in java is a class whose objects wraps or contains primitive datatypes
Need:
They convert primitive datatypes into objects
In collection framework, such as Arraylist and sets,will store only objects and not primitive datatypes
Primitive datatypes Wrapper classes
char————————Character
int————————-Integer
float———————–Float
double———————–Double
boolean———————Booelan
byte————————Byte
short———————–Short
long————————Long
2 types:
–>Autoboxing[Conversion of primitive datatypes into objects]
–>Auto unboxing[Conversion of objects into primitive datatype]
import java.util.*;
class ASC
{
public static void main(String args[])
{
int num=7;//7 kept num belongs to datatype
//Integer num1=new Integer(num);//boxing
Integer a=num;//autoboxing
System.out.println(a);
System.out.println(a“ instanceof Integer);//num1 is an object of Integer class
}
}
————————————
import java.util.*;
class ASC
{
public static void main(String args[])
{
int num=7;//7 kept num belongs to int datatype
Integer a=num;//autoboxing
int b=a;//auto-unboxing
System.out.println(a);
System.out.println(a instanceof Integer);//num1 is an object of Integer class
System.out.println(b);
System.out.println(b instanceof Integer);
}
}