---
title: "Difference between boxing and unboxing?"  
description: "Difference between boxing and unboxing?"  
author: "Hemant Patel"  
published: 2017-03-02  
updated: 2020-09-24  
canonical: https://www.mindstick.com/interview/23216/difference-between-boxing-and-unboxing  
category: "java"  
tags: ["java"]  
reading_time: 1 minute  

---

# Difference between boxing and unboxing?

The automatic conversion of primitive data types into it’s equivalent wrapper type is known as boxing and when wrapper type convert into its equivalent primitive data types is known as unboxing.

**Example of Boxing in java:**

```
class Boxing         {         public static void main(string args[])          {           Int x=10;           Integer y=new Integer(x); //boxing           Integer z=15; //boxing          System.out.println(y+” ”+z);          }         }
```

**Example of Unboxing in java:**

```
Class Unboxing         {          public static void main(string args[])          {          Integer x=new Integer(11); //Unboxing          Int y=x; //Unboxing          System.out.println(y);          }         }
```

## Answers

### Answer by Hemant Patel

The automatic conversion of primitive data types into it’s equivalent wrapper type is known as boxing and when wrapper type convert into its equivalent primitive data types is known as unboxing.

**Example of Boxing in java:**

```
class Boxing         {         public static void main(string args[])          {           Int x=10;           Integer y=new Integer(x); //boxing           Integer z=15; //boxing          System.out.println(y+” ”+z);          }         }
```

**Example of Unboxing in java:**

```
Class Unboxing         {          public static void main(string args[])          {          Integer x=new Integer(11); //Unboxing          Int y=x; //Unboxing          System.out.println(y);          }         }
```


---

Original Source: https://www.mindstick.com/interview/23216/difference-between-boxing-and-unboxing

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
