{"id":25532597,"date":"2022-07-08T15:00:43","date_gmt":"2022-07-08T09:30:43","guid":{"rendered":"https:\/\/entri.app\/blog\/?p=25532597"},"modified":"2022-11-19T16:56:17","modified_gmt":"2022-11-19T11:26:17","slug":"autoboxing-and-unboxing-in-java-how-does-it-work","status":"publish","type":"post","link":"https:\/\/entri.app\/blog\/autoboxing-and-unboxing-in-java-how-does-it-work\/","title":{"rendered":"Autoboxing and Unboxing in Java: How does it Work?"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_79_2 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69e4e89253f26\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69e4e89253f26\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/entri.app\/blog\/autoboxing-and-unboxing-in-java-how-does-it-work\/#What_is_Autoboxing_in_Java\" >What is Autoboxing in Java?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/entri.app\/blog\/autoboxing-and-unboxing-in-java-how-does-it-work\/#How_does_it_work\" >How does it work?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/entri.app\/blog\/autoboxing-and-unboxing-in-java-how-does-it-work\/#Why_Should_I_Care_About_Autoboxing\" >Why Should I Care About Autoboxing?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/entri.app\/blog\/autoboxing-and-unboxing-in-java-how-does-it-work\/#What_Types_Are_Involved_With_Auto-Unboxing\" >What Types Are Involved With Auto-Unboxing?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/entri.app\/blog\/autoboxing-and-unboxing-in-java-how-does-it-work\/#Why_Autoboxing_Is_Needed_To_Analyze_That_Question\" >Why Autoboxing Is Needed, To Analyze That Question?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/entri.app\/blog\/autoboxing-and-unboxing-in-java-how-does-it-work\/#When_Do_You_Use_Auto-Boxing_And_When_Do_You_Use_Auto-Unboxing\" >When Do You Use Auto-Boxing And When Do You Use Auto-Unboxing<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/entri.app\/blog\/autoboxing-and-unboxing-in-java-how-does-it-work\/#Final_Word_On_The_Subject_Of_Auto-Boxing_And_Unboxing_In_Java\" >Final Word On The Subject Of Auto-Boxing And Unboxing In Java<\/a><\/li><\/ul><\/nav><\/div>\n<p>Autoboxing, also known as unboxing, in Java is the process of converting primitives to their primitive wrapper types and vice versa. Autoboxing in java<span data-slate-fragment=\"JTVCJTdCJTIydHlwZSUyMiUzQSUyMnBhcmFncmFwaCUyMiUyQyUyMmNoaWxkcmVuJTIyJTNBJTVCJTdCJTIydGV4dCUyMiUzQSUyMkF1dG9ib3hpbmclMjBhbmQlMjB1bmJveGluZyUyMGluJTIwSmF2YSUyMGNhbiUyMHNlZW0lMjB2ZXJ5JTIwY29uZnVzaW5nJTIwYXQlMjBmaXJzdCUyQyUyMGJ1dCUyMHdpdGglMjB0aGUlMjByaWdodCUyMGd1aWRhbmNlJTIweW91JTIwY2FuJTIwZWFzaWx5JTIwbGVhcm4lMjBob3clMjBpdCUyMHdvcmtzLiUyMElmJTIweW91JUUyJTgwJTk5cmUlMjBjdXJpb3VzJTIwYWJvdXQlMjBhdXRvYm94aW5nJTIwYW5kJTIwdW5ib3hpbmclMjBpbiUyMEphdmElMkMlMjB0aGlzJTIwZ3VpZGUlMjBoYXMlMjBldmVyeXRoaW5nJTIweW91JTIwbmVlZCUyMHRvJTIwa25vdyUyMHRvJTIwZ2V0JTIwc3RhcnRlZCElMjIlN0QlNUQlN0QlNUQ=\"> and unboxing in Java can seem very confusing at first, but with the right guidance, you can easily learn how it works. If you\u2019re curious about autoboxing and unboxing, this guide has everything you need to know to get started! <a href=\"https:\/\/entri.app\/blog\/why-java-is-not-a-purely-object-oriented-language\/\" target=\"_blank\" rel=\"noopener\">Autoboxing and<\/a> unboxing in Java might sound a little like technology from the future, but you might be surprised to learn that they are actually a lot simpler than you think. As part of this introductory guide on autoboxing and unboxing, we\u2019ll look at what exactly these terms mean and how to use them effectively within your code. After reading this article, you\u2019ll have the knowledge necessary to write efficient Java code that saves you time and effort when working with primitives. Let\u2019s get started!<\/span><\/p>\n<h2><a href=\"https:\/\/entri.sng.link\/Bcofz\/yeoy\/ojyv\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-25531373 size-full\" src=\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/07\/Python-and-Machine-Learning-Rectangle-1.png\" alt=\"\" width=\"970\" height=\"250\" srcset=\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/07\/Python-and-Machine-Learning-Rectangle-1.png 970w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/07\/Python-and-Machine-Learning-Rectangle-1-300x77.png 300w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/07\/Python-and-Machine-Learning-Rectangle-1-768x198.png 768w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/07\/Python-and-Machine-Learning-Rectangle-1-750x193.png 750w\" sizes=\"auto, (max-width: 970px) 100vw, 970px\" \/><\/a><\/h2>\n<h2><span class=\"ez-toc-section\" id=\"What_is_Autoboxing_in_Java\"><\/span><strong>What is Autoboxing in Java?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Autoboxing in java is the automatic conversion that the Java compiler makes between the primitive types and their corresponding object wrapper classes. For example, converting an int to an Integer. This is called autoboxing because it happens automatically, without any programmer intervention. There are also many other cases where autoboxing is used to convert one type of object into another; for example when passing an array as a parameter. What is unboxing?: When you use any kind of Object in your code, Java will always first try to determine what type the Object really is. It does this by looking at its class and then using these rules If the class has a <a href=\"https:\/\/entri.sng.link\/Bcofz\/uu8c\/w409\">no-argument constructor<\/a>, Java will simply call newInstance(). Otherwise, it will instantiate the object using newInstance(), but with explicit type information. If there is only one possible match (e.g., java.lang.Integer), Java knows that there is no need to do anything else, so it skips ahead. But if there are two or more possible matches (e.g., java.lang.Integer and java.lang .Float), Java must decide which constructor to call based on which match can be made with minimum casts. That is why you often see things like Integer i = new Integer(5); even though 5 could be represented as either an integer or a float, since we know that the variable should have been initialized as an integer, Java will cast 5 to an Integer and create a new instance of Integer. In contrast, casting a String to an Integer would not make sense, so Java won&#8217;t allow it.<\/p>\n<p style=\"text-align: center;\"><strong><a href=\"https:\/\/bit.ly\/3ELmCiA\" target=\"_blank\" rel=\"noopener\">Learn Coding in your Language! Enroll Here!<\/a><\/strong><\/p>\n<h2><span class=\"ez-toc-section\" id=\"How_does_it_work\"><\/span><strong>How does it work?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Autoboxing is the automatic conversion that the Java compiler makes between the primitive types and their corresponding object wrapper classes. For example, converting an int to an Integer. This is called autoboxing because the primitive is automatically boxed into an object. Unboxing is just the opposite: it&#8217;s when the Java compiler converts an object back into a primitive. The simplest way to think about unboxing is that it&#8217;s the reverse of boxing. An Integer instance can be turned into an int by unboxing it from its outer wrapping box class &#8211; either from itself or from another type such as String. However, there are restrictions on what kind of numeric data you can unbox. You cannot unbox any <a href=\"https:\/\/entri.sng.link\/Bcofz\/uu8c\/w409\">negative numbers<\/a> (e.g., you cannot take the Int instance 10 and turn it into a long) nor any numbers that would result in overflow errors (e.g., turning 3\/2 into an Int). You also cannot use byte values with operators like + or &#8211; since byte values are unsigned which will cause overflow errors if they&#8217;re used with these operators. When we talk about unboxing, it&#8217;s often said that unboxing removes the wrapping. When an object is unboxed, the value is copied from the Object instance to a new variable of its original type. In order for this to work, however, the code must have access to both variables at once. If they&#8217;re not visible at the same time, then one of them needs to be assigned before unboxing and then reassigned after it.<\/p>\n<p style=\"text-align: center;\"><strong><a href=\"https:\/\/bit.ly\/3ELmCiA\">Enroll in our latest java programming course in the Entri app!<\/a><\/strong><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Why_Should_I_Care_About_Autoboxing\"><\/span><strong>Why Should I Care About Autoboxing?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Autoboxing in java is the automatic conversion that the Java compiler makes between the primitive types and their corresponding object wrapper classes. For example, you are converting an int to an Integer. This is important because it allows for code to be more concise and less error-prone. Plus, it can make working with nulls easier and can help prevent accidental errors. There are two ways that you can use autoboxing: (1) You can just write a line like this int a = 5; which <a href=\"https:\/\/entri.sng.link\/Bcofz\/uu8c\/w409\">automatically creates<\/a> an Integer object and assigns its value to variable a or (2) You may want to create your own objects instead of using autoboxing which would look like this Integer b = new Integer(5);. In either case, both a and b will have the same value. It&#8217;s also worth noting that if you call any of the methods on Integer (such as parseInt()), they will work on both an int or Integer object and return the correct result. If you pass in a String, these methods will convert it to an int first before doing anything else with it so beware! If you need to do the math on Strings and other data types, always make sure to cast them explicitly. Finally, it&#8217;s worth noting that the reason why auto boxing is possible is that every primitive type has an equivalent class type: byte -&gt; Byte<br \/>\nA byte -&gt; Byte<br \/>\nshort -&gt; Short<br \/>\nint -&gt; Integer<br \/>\nlong -&gt; Long<br \/>\nfloat -&gt; Float<br \/>\ndouble -&gt; Double char -&gt; Character<br \/>\nboolean -&gt; Boolean<\/p>\n<h2><span class=\"ez-toc-section\" id=\"What_Types_Are_Involved_With_Auto-Unboxing\"><\/span><strong>What Types Are Involved With Auto-Unboxing?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>In Java, there are two types that are involved with auto-unboxing: the primitive type and the reference type. The primitive type is the most basic data type available in Java. These include boolean, byte, short, int, long, float, and double. The reference type is any object that is not a primitive data type. This includes objects such as strings, arrays, and classes. It should be noted that when an object is created, it starts out as a boxed value. When this happens, the instance must<a href=\"https:\/\/entri.sng.link\/Bcofz\/uu8c\/w409\"> go through<\/a> the unboxing process before it can be used. To do this, Java will first see if there is a constructor for the boxed value or if it has been explicitly converted to another type via a cast operator. If no conversion can be found for the boxed value then an exception will occur because java does not know how to create an instance of that particular class. An example of this would be if we had attempted to use a string that had been boxed by putting java.lang. in front of it.<\/p>\n<p style=\"text-align: center;\"><strong><a href=\"https:\/\/bit.ly\/3ELmCiA\">Get the latest updates on java programming in the Entri App!<\/a><\/strong><\/p>\n<p>There is no way to convert this boxed value into the String type so Java would need explicit instruction on what string needs to happen next. In order for these instructions to take place, programmers must have knowledge about both autoboxing and unboxing\u00a0 as well as what each one entails so they can choose which one they want based on their needs at the time. For example, let&#8217;s say that we needed to concatenate a string together using + operators. We could do this <a href=\"https:\/\/entri.sng.link\/Bcofz\/uu8c\/w409\">using autoboxing<\/a> but would also have the option of using unboxing as well if desired. For someone who wants to avoid creating unnecessary temporary variables (thus saving memory), choosing autoboxing may be best; however, for someone who needs better performance from the system and doesn&#8217;t mind creating more temporary variables (thus consuming more memory), choosing to unbox may be best.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Why_Autoboxing_Is_Needed_To_Analyze_That_Question\"><\/span><strong>Why Autoboxing Is Needed, To Analyze That Question?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>In computer programming, autoboxing is the automatic conversion that the Java compiler makes between the primitive types (such as int) and their corresponding object wrapper classes (such as Integer). For example, converting an int to an Integer is called autoboxing. The reverse process, converting an Integer back into an int, is called unboxing. Autoboxing and unboxing allow primitive types to be used as if they were objects. One common use for this is when a class defines two methods: one with a parameter of type Object, and one with a parameter of type Integer. It would be <a href=\"https:\/\/entri.sng.link\/Bcofz\/uu8c\/w409\">inconvenient to always<\/a> have to pass an object reference instead of an Integer value; therefore, the compiler automatically inserts code at compile time that converts from integers to Objects as needed or vice versa. Autoboxing also occurs whenever two boxed values are assigned where only one needs to be boxed\u2014the other value will then become unboxed automatically without the programmer having explicitly written any code for it. To see how autoboxing works, we can create a new method on the Integer class which takes an integer argument and returns its double equivalent.<br \/>\n#include Integer.java public static double getDouble(int n){ return n*2;}<br \/>\nThis method compiles fine because we are operating on primitives within the same type family. We can now invoke our new method:<br \/>\nSystem.out.println(double of 5 = + getDouble(5)); \/\/double of 5 = 10<\/p>\n<h2><span class=\"ez-toc-section\" id=\"When_Do_You_Use_Auto-Boxing_And_When_Do_You_Use_Auto-Unboxing\"><\/span><strong>When Do You Use Auto-Boxing And When Do You Use Auto-Unboxing<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>You use auto-boxing when you assign a primitive value to an object reference. You use auto-unboxing when you assign an object reference to a primitive value. There are four situations where autoboxing\/unboxing occurs: assignment, method invocation, equality\/relational comparisons, and casting. Let&#8217;s take a look at each of these scenarios in more detail below. The assignment is the <a href=\"https:\/\/entri.sng.link\/Bcofz\/uu8c\/w409\">most common<\/a> scenario for auto-boxing and unboxing. Consider the following snippet of code: A person has just moved into a new apartment! They have all their boxes from their old house delivered, but they don&#8217;t have any furniture yet! They need something to put on the floor so they can start unpacking boxes. Luckily for them, their friend has offered up some sturdy cardboard boxes that should do the trick! The friend tells them that they can take as many as they want from his basement (so long as he doesn&#8217;t find out).<\/p>\n<p style=\"text-align: center;\"><strong><a href=\"https:\/\/bit.ly\/3ELmCiA\">Enroll in our latest java programming course in the Entri App!<\/a><\/strong><\/p>\n<p>So our person makes their way down into his basement only to find hundreds of cardboard boxes stacked high on shelves stretching across one wall &#8211; there must be enough cardboard boxes here for everyone in the neighborhood! Our person grabs ten boxes and starts back upstairs. But what if the person had wanted eleven? Well, that would have been impossible because a box isn&#8217;t an object with methods like add() or remove(). Our friend would not be happy about this <a href=\"https:\/\/entri.sng.link\/Bcofz\/uu8c\/w409\">either because<\/a> it means someone else got to steal away his precious cardboard containers! In order to solve this problem, we need to introduce boxing. To make this happen, we&#8217;ll turn the box into an object by writing Box as follows: A Person has just moved into a new apartment! They have all their boxes from their old house delivered, but they don&#8217;t have any furniture yet! They need something to put on the floor so they can start unpacking boxes.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Final_Word_On_The_Subject_Of_Auto-Boxing_And_Unboxing_In_Java\"><\/span><strong>Final Word On The Subject Of Auto-Boxing And Unboxing In Java<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Auto-boxing and unboxing is a handy feature of the Java language that can help make your code more concise and readable. However, it&#8217;s important to understand how the process works so that you can avoid potential errors. In general, auto-boxing is performed when a primitive value is assigned to a reference variable, while unboxing is the reverse process of converting a reference variable back into a primitive value. With that said, there are some caveats to be aware of when using these features. First, unboxing will only work if the reference variable contains a compatible<a href=\"https:\/\/entri.sng.link\/Bcofz\/uu8c\/w409\"> primitive value<\/a>; attempting to unbox an incompatible value will result in an error. Second, by default java will automatically box any type of object into its equivalent wrapper class. The reasoning behind this has to do with efficiency: rather than requiring programmers to manually create objects every time they need one, the Java language automates this step by making use of pre-built objects (e.g., Integer) whenever possible.<\/p>\n<p>And finally, last but not least &#8211; what happens when we mix the two? If you assign a boxed object (e.g., Integer) to a primitive type variable (e.g., int), then you&#8217;re actually giving an int object (i.e., new Integer(123)) to that variable instead &#8211; so keep this in mind when <a href=\"https:\/\/entri.sng.link\/Bcofz\/uu8c\/w409\">accessing object<\/a> methods or fields! Unwrapping an Object to get at the underlying Value: If you assign a boxed object (e.g., Integer) to a primitive type variable (e.g., int), then you&#8217;re actually assigning an int object (i.e., new Integer(123)) to that variable instead &#8211; so keep this in mind when accessing object methods or fields! If you are interested to learn new coding skills, the Entri app will help you to acquire them very easily. Entri app is following a structural study plan so that the students can learn very easily. If you don&#8217;t have a coding background, it won&#8217;t be a problem. You can download the Entri app from the google play store and enroll in your favorite course.<\/p>\n<p style=\"text-align: center;\"><strong><a href=\"https:\/\/bit.ly\/3ELmCiA\">Get the latest updates on java programming in the Entri App!<\/a><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Autoboxing, also known as unboxing, in Java is the process of converting primitives to their primitive wrapper types and vice versa. Autoboxing in java and unboxing in Java can seem very confusing at first, but with the right guidance, you can easily learn how it works. If you\u2019re curious about autoboxing and unboxing, this guide [&hellip;]<\/p>\n","protected":false},"author":93,"featured_media":25532601,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[802,1864,1882,1883,1881],"tags":[],"class_list":["post-25532597","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-articles","category-data-science-ml","category-java-programming","category-react-native","category-web-android-development"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Autoboxing and Unboxing in Java: How does it Work? - Entri Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/entri.app\/blog\/autoboxing-and-unboxing-in-java-how-does-it-work\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Autoboxing and Unboxing in Java: How does it Work? - Entri Blog\" \/>\n<meta property=\"og:description\" content=\"Autoboxing, also known as unboxing, in Java is the process of converting primitives to their primitive wrapper types and vice versa. Autoboxing in java and unboxing in Java can seem very confusing at first, but with the right guidance, you can easily learn how it works. If you\u2019re curious about autoboxing and unboxing, this guide [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/entri.app\/blog\/autoboxing-and-unboxing-in-java-how-does-it-work\/\" \/>\n<meta property=\"og:site_name\" content=\"Entri Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/entri.me\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-07-08T09:30:43+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-11-19T11:26:17+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/07\/Untitled-90-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"820\" \/>\n\t<meta property=\"og:image:height\" content=\"615\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Akhil M G\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@entri_app\" \/>\n<meta name=\"twitter:site\" content=\"@entri_app\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Akhil M G\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"11 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/entri.app\/blog\/autoboxing-and-unboxing-in-java-how-does-it-work\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/entri.app\/blog\/autoboxing-and-unboxing-in-java-how-does-it-work\/\"},\"author\":{\"name\":\"Akhil M G\",\"@id\":\"https:\/\/entri.app\/blog\/#\/schema\/person\/875646423b2cce93c1bd5bc16850fff6\"},\"headline\":\"Autoboxing and Unboxing in Java: How does it Work?\",\"datePublished\":\"2022-07-08T09:30:43+00:00\",\"dateModified\":\"2022-11-19T11:26:17+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/entri.app\/blog\/autoboxing-and-unboxing-in-java-how-does-it-work\/\"},\"wordCount\":2265,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/entri.app\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/entri.app\/blog\/autoboxing-and-unboxing-in-java-how-does-it-work\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/07\/Untitled-90-1.png\",\"articleSection\":[\"Articles\",\"Data Science and Machine Learning\",\"Java Programming\",\"React Native\",\"Web and Android Development\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/entri.app\/blog\/autoboxing-and-unboxing-in-java-how-does-it-work\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/entri.app\/blog\/autoboxing-and-unboxing-in-java-how-does-it-work\/\",\"url\":\"https:\/\/entri.app\/blog\/autoboxing-and-unboxing-in-java-how-does-it-work\/\",\"name\":\"Autoboxing and Unboxing in Java: How does it Work? - Entri Blog\",\"isPartOf\":{\"@id\":\"https:\/\/entri.app\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/entri.app\/blog\/autoboxing-and-unboxing-in-java-how-does-it-work\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/entri.app\/blog\/autoboxing-and-unboxing-in-java-how-does-it-work\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/07\/Untitled-90-1.png\",\"datePublished\":\"2022-07-08T09:30:43+00:00\",\"dateModified\":\"2022-11-19T11:26:17+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/entri.app\/blog\/autoboxing-and-unboxing-in-java-how-does-it-work\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/entri.app\/blog\/autoboxing-and-unboxing-in-java-how-does-it-work\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/entri.app\/blog\/autoboxing-and-unboxing-in-java-how-does-it-work\/#primaryimage\",\"url\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/07\/Untitled-90-1.png\",\"contentUrl\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/07\/Untitled-90-1.png\",\"width\":820,\"height\":615,\"caption\":\"Autoboxing and Unboxing in Java: How does it Work?\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/entri.app\/blog\/autoboxing-and-unboxing-in-java-how-does-it-work\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/entri.app\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Entri Skilling\",\"item\":\"https:\/\/entri.app\/blog\/category\/entri-skilling\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Java Programming\",\"item\":\"https:\/\/entri.app\/blog\/category\/entri-skilling\/java-programming\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Autoboxing and Unboxing in Java: How does it Work?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/entri.app\/blog\/#website\",\"url\":\"https:\/\/entri.app\/blog\/\",\"name\":\"Entri Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/entri.app\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/entri.app\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/entri.app\/blog\/#organization\",\"name\":\"Entri App\",\"url\":\"https:\/\/entri.app\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/entri.app\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2019\/10\/Entri-Logo-1.png\",\"contentUrl\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2019\/10\/Entri-Logo-1.png\",\"width\":989,\"height\":446,\"caption\":\"Entri App\"},\"image\":{\"@id\":\"https:\/\/entri.app\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/entri.me\/\",\"https:\/\/x.com\/entri_app\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/entri.app\/blog\/#\/schema\/person\/875646423b2cce93c1bd5bc16850fff6\",\"name\":\"Akhil M G\",\"url\":\"https:\/\/entri.app\/blog\/author\/akhil\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Autoboxing and Unboxing in Java: How does it Work? - Entri Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/entri.app\/blog\/autoboxing-and-unboxing-in-java-how-does-it-work\/","og_locale":"en_US","og_type":"article","og_title":"Autoboxing and Unboxing in Java: How does it Work? - Entri Blog","og_description":"Autoboxing, also known as unboxing, in Java is the process of converting primitives to their primitive wrapper types and vice versa. Autoboxing in java and unboxing in Java can seem very confusing at first, but with the right guidance, you can easily learn how it works. If you\u2019re curious about autoboxing and unboxing, this guide [&hellip;]","og_url":"https:\/\/entri.app\/blog\/autoboxing-and-unboxing-in-java-how-does-it-work\/","og_site_name":"Entri Blog","article_publisher":"https:\/\/www.facebook.com\/entri.me\/","article_published_time":"2022-07-08T09:30:43+00:00","article_modified_time":"2022-11-19T11:26:17+00:00","og_image":[{"width":820,"height":615,"url":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/07\/Untitled-90-1.png","type":"image\/png"}],"author":"Akhil M G","twitter_card":"summary_large_image","twitter_creator":"@entri_app","twitter_site":"@entri_app","twitter_misc":{"Written by":"Akhil M G","Est. reading time":"11 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/entri.app\/blog\/autoboxing-and-unboxing-in-java-how-does-it-work\/#article","isPartOf":{"@id":"https:\/\/entri.app\/blog\/autoboxing-and-unboxing-in-java-how-does-it-work\/"},"author":{"name":"Akhil M G","@id":"https:\/\/entri.app\/blog\/#\/schema\/person\/875646423b2cce93c1bd5bc16850fff6"},"headline":"Autoboxing and Unboxing in Java: How does it Work?","datePublished":"2022-07-08T09:30:43+00:00","dateModified":"2022-11-19T11:26:17+00:00","mainEntityOfPage":{"@id":"https:\/\/entri.app\/blog\/autoboxing-and-unboxing-in-java-how-does-it-work\/"},"wordCount":2265,"commentCount":0,"publisher":{"@id":"https:\/\/entri.app\/blog\/#organization"},"image":{"@id":"https:\/\/entri.app\/blog\/autoboxing-and-unboxing-in-java-how-does-it-work\/#primaryimage"},"thumbnailUrl":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/07\/Untitled-90-1.png","articleSection":["Articles","Data Science and Machine Learning","Java Programming","React Native","Web and Android Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/entri.app\/blog\/autoboxing-and-unboxing-in-java-how-does-it-work\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/entri.app\/blog\/autoboxing-and-unboxing-in-java-how-does-it-work\/","url":"https:\/\/entri.app\/blog\/autoboxing-and-unboxing-in-java-how-does-it-work\/","name":"Autoboxing and Unboxing in Java: How does it Work? - Entri Blog","isPartOf":{"@id":"https:\/\/entri.app\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/entri.app\/blog\/autoboxing-and-unboxing-in-java-how-does-it-work\/#primaryimage"},"image":{"@id":"https:\/\/entri.app\/blog\/autoboxing-and-unboxing-in-java-how-does-it-work\/#primaryimage"},"thumbnailUrl":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/07\/Untitled-90-1.png","datePublished":"2022-07-08T09:30:43+00:00","dateModified":"2022-11-19T11:26:17+00:00","breadcrumb":{"@id":"https:\/\/entri.app\/blog\/autoboxing-and-unboxing-in-java-how-does-it-work\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/entri.app\/blog\/autoboxing-and-unboxing-in-java-how-does-it-work\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/entri.app\/blog\/autoboxing-and-unboxing-in-java-how-does-it-work\/#primaryimage","url":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/07\/Untitled-90-1.png","contentUrl":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/07\/Untitled-90-1.png","width":820,"height":615,"caption":"Autoboxing and Unboxing in Java: How does it Work?"},{"@type":"BreadcrumbList","@id":"https:\/\/entri.app\/blog\/autoboxing-and-unboxing-in-java-how-does-it-work\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/entri.app\/blog\/"},{"@type":"ListItem","position":2,"name":"Entri Skilling","item":"https:\/\/entri.app\/blog\/category\/entri-skilling\/"},{"@type":"ListItem","position":3,"name":"Java Programming","item":"https:\/\/entri.app\/blog\/category\/entri-skilling\/java-programming\/"},{"@type":"ListItem","position":4,"name":"Autoboxing and Unboxing in Java: How does it Work?"}]},{"@type":"WebSite","@id":"https:\/\/entri.app\/blog\/#website","url":"https:\/\/entri.app\/blog\/","name":"Entri Blog","description":"","publisher":{"@id":"https:\/\/entri.app\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/entri.app\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/entri.app\/blog\/#organization","name":"Entri App","url":"https:\/\/entri.app\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/entri.app\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2019\/10\/Entri-Logo-1.png","contentUrl":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2019\/10\/Entri-Logo-1.png","width":989,"height":446,"caption":"Entri App"},"image":{"@id":"https:\/\/entri.app\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/entri.me\/","https:\/\/x.com\/entri_app"]},{"@type":"Person","@id":"https:\/\/entri.app\/blog\/#\/schema\/person\/875646423b2cce93c1bd5bc16850fff6","name":"Akhil M G","url":"https:\/\/entri.app\/blog\/author\/akhil\/"}]}},"_links":{"self":[{"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/posts\/25532597","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/users\/93"}],"replies":[{"embeddable":true,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/comments?post=25532597"}],"version-history":[{"count":4,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/posts\/25532597\/revisions"}],"predecessor-version":[{"id":25547412,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/posts\/25532597\/revisions\/25547412"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/media\/25532601"}],"wp:attachment":[{"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/media?parent=25532597"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/categories?post=25532597"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/tags?post=25532597"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}