EduLearn - Online Education Platform

Welcome to EduLearn!

Start learning today with our wide range of courses taught by industry experts. Gain new skills, advance your career, or explore new interests.

Browse Courses

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);

 

}

}

Wrapper classes in java

Leave a Reply

Your email address will not be published. Required fields are marked *

EduLearn - Online Education Platform

Welcome to EduLearn!

Start learning today with our wide range of courses taught by industry experts. Gain new skills, advance your career, or explore new interests.

Browse Courses

Popular Courses

[Course Image]

Introduction to Programming

Learn the fundamentals of programming with Python in this beginner-friendly course.

12 Hours Beginner
[Course Image]

Data Science Essentials

Master the basics of data analysis, visualization, and machine learning.

20 Hours Intermediate
[Course Image]

Web Development Bootcamp

Build modern websites with HTML, CSS, JavaScript and popular frameworks.

30 Hours Beginner
[Course Image]

Digital Marketing Fundamentals

Learn SEO, social media marketing, email campaigns and analytics.

15 Hours Beginner
Educational Website Footer