{"id":77198,"date":"2020-03-16T10:15:05","date_gmt":"2020-03-16T04:45:05","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=77198"},"modified":"2020-03-16T10:15:05","modified_gmt":"2020-03-16T04:45:05","slug":"java-wrapper-class","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/java-wrapper-class\/","title":{"rendered":"Wrapper Class in Java &#8211; Learn Autoboxing &amp; Unboxing with Coding Examples"},"content":{"rendered":"<p>Java is not a purely object-oriented programming language, the reason being it works on primitive data types. These eight primitive data types int, short, byte, long, float, double, char and, boolean are not objects.<\/p>\n<p>We use wrapper classes to use these data types in the form of objects. Wrapper class in Java makes the Java code fully object-oriented. For example, converting an int to Integer. Here int is a data type and Integer is the wrapper class of int.<\/p>\n<p>We will discuss the concept of wrapper classes in Java with the examples. There are several reasons why we prefer a wrapper class instead of a primitive type; we will discuss them as well in this article. We will also discuss Autoboxing and Unboxing in Java.<\/p>\n<p><em><strong>Let&#8217;s take a quick revision on <a href=\"https:\/\/techvidvan.com\/tutorials\/data-types-in-java\/\">Data Types in Java<\/a> to clear your basics with Techvidvan.\u00a0<\/strong><\/em><\/p>\n<h3>Wrapper class in Java<\/h3>\n<p>Sometimes in the process of development, we come across situations where there is a need for objects instead of primitive data types. To achieve this, Java provides a concept of Wrapper classes.<\/p>\n<p>A <strong>Wrapper class<\/strong> in Java is the type of class that provides a mechanism to convert the primitive data types into the objects and vice-versa.<\/p>\n<p>When a wrapper class is created, there is a creation of a new field in which we store the primitive data types. The object of the wrapper class wraps or holds its respective primitive data type.<\/p>\n<p>The process of converting primitive data types into an object is called boxing. While using a wrapper class, you just have to pass the value of the primitive data type to the constructor of the Wrapper class.<\/p>\n<p>All the wrapper classes Byte, Short, Integer, Long, Double and, Float, are subclasses of the abstract class <strong>Number.<\/strong> While Character and Boolean wrapper classes are the subclasses of class <strong>Object.<\/strong><\/p>\n<p>The diagram below shows the hierarchy of the wrapper classes.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/03\/java-wrapper-class-hierarchy.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-77512\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/03\/java-wrapper-class-hierarchy.jpg\" alt=\"Java Wrapper Class Hierarchy\" width=\"530\" height=\"542\" \/><\/a><\/p>\n<table class=\"tv-table-center\">\n<tbody>\n<tr>\n<td><b>Primitive Data Type<\/b><\/td>\n<td><b>Wrapper Class<\/b><\/td>\n<td><b>Constructor Argument<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">boolean<\/span><\/td>\n<td><b>Boolean<\/b><\/td>\n<td><span style=\"font-weight: 400\">boolean or String<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">byte<\/span><\/td>\n<td><b>Byte<\/b><\/td>\n<td><span style=\"font-weight: 400\">byte or String<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">char<\/span><\/td>\n<td><b>Character<\/b><\/td>\n<td><span style=\"font-weight: 400\">char<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">int<\/span><\/td>\n<td><b>Integer<\/b><\/td>\n<td><span style=\"font-weight: 400\">int or String<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">float<\/span><\/td>\n<td><b>Float<\/b><\/td>\n<td><span style=\"font-weight: 400\">float, double or String<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">double<\/span><\/td>\n<td><b>Double<\/b><\/td>\n<td><span style=\"font-weight: 400\">double or String<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">long<\/span><\/td>\n<td><b>Long<\/b><\/td>\n<td><span style=\"font-weight: 400\">long or String<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">short<\/span><\/td>\n<td><b>Short<\/b><\/td>\n<td><span style=\"font-weight: 400\">short or String<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Need for Wrapper class in Java<\/h3>\n<ul>\n<li>Wrapper classes are used to provide a mechanism to \u2018wrap\u2019 or bind the values of primitive data types into an object. This helps primitives types act like objects and do the activities reserved for objects like we can add these converted types to the collections like ArrayList, HashSet, HashMap, etc.<\/li>\n<li>Wrapper classes are also used to provide a variety of utility functions for primitives data types like converting primitive types to string objects and vice-versa, converting to various bases like binary, octal or <a href=\"https:\/\/en.wikipedia.org\/wiki\/Hexadecimal\">hexadecimal<\/a>, or comparing various objects.<\/li>\n<li>We can not provide null values to Primitive types but wrapper classes can be null. So wrapper classes can be used in such cases we want to assign a null value to primitive data types.<\/li>\n<\/ul>\n<h3>Advantages of using Wrapper class in Java<\/h3>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/03\/advantages-of-wrapper-class-in-java.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-77513\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/03\/advantages-of-wrapper-class-in-java.jpg\" alt=\"Java Wrapper Class Advantages\" width=\"802\" height=\"420\" \/><\/a><\/p>\n<p><strong>1. Serialization:<\/strong> In Serialization, We need to convert the objects into streams. If we have a primitive value and we want to serialize them then we can do this by converting them with the help of wrapper classes.<\/p>\n<p><strong>2. Synchronization:<\/strong> In Multithreading, Java synchronization works with objects.<\/p>\n<p><strong>3. java.util package:<\/strong> The package java.util provides many utility classes to deal with objects rather than values.<\/p>\n<p><strong>4. Collection Framework:<\/strong> The Collection Framework in Java works only with objects. All classes of the collection framework like ArrayList, LinkedList, Vector, HashSet, LinkedHashSet, TreeSet, PriorityQueue, ArrayDeque, etc, work only with objects.<\/p>\n<p><strong>5. Changing the value inside a Method:<\/strong> So, if we pass a primitive value using call by value, it will not change the original value. But, it will change the original value if we convert the primitive value into an object.<\/p>\n<p><strong>6. Polymorphism:<\/strong> Wrapper classes also help in achieving Polymorphism in Java.<\/p>\n<p><em><strong>Get to know about <a href=\"https:\/\/techvidvan.com\/tutorials\/java-polymorphism\/\">Java Polymorphism<\/a> in detail with Techvidvan.<\/strong><\/em><\/p>\n<h3>Creating Wrapper Objects<\/h3>\n<p>We use the wrapper class to create an object of the wrapper class. To get the value of the data type, we can just print the object.<\/p>\n<p><strong>Code to illustrate the creation of Wrapper Objects:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.techvidvan.wrapperclasses;\npublic class WrapperDemo\n{\n  public static void main(String[] args)\n  {\n    Integer myInt = 10;\n    Double myDouble = 11.65;\n    Character myChar = 'T';\n    Boolean myBool= true;\n\n    System.out.println(myInt);\n    System.out.println(myDouble);\n    System.out.println(myChar);\n    System.out.println(myBool);\n  }\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">10<br \/>\n11.65<br \/>\nT<br \/>\ntrue<\/div>\n<h3>Autoboxing and Unboxing in Java<\/h3>\n<h4>1. Autoboxing<\/h4>\n<p>The process to automatically convert the primitive data types into corresponding wrapper class objects is called Autoboxing in Java. This is Autoboxing because this is done automatically by the Java compiler.<\/p>\n<p>For example, char to Character, int to Integer, long to Long, double to Double, float to Float, boolean to Boolean, byte to Byte, and short to Short.<\/p>\n<p><strong>Code to understand Autoboxing in Java:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.techvidvan.wrapperclasses;\nimport java.util.ArrayList;\npublic class AutoboxingExample\n{\n  public static void main(String[] args)\n  {\n    \/\/Converting an int primitive data type into an Integer object\n    int number = 15;\n    Integer obj=Integer.valueOf(number); \/\/converting int into Integer explicitly\n    System.out.println(number+ \" \"+ obj);\n\n    \/\/Converting char primitive data type into a Character object\n    char character = 'a';\n    Character obj1 = character;\n    System.out.println(character+ \" \"+ obj1);\n\n    \/\/Using Collection Framework\n    ArrayList&lt;Integer&gt; arrayList = new ArrayList&lt;Integer&gt;();\n    arrayList.add(16); \/\/Autoboxing\n    arrayList.add(35); \/\/Autoboxing\n    System.out.println(arrayList.get(0));\n    System.out.println(arrayList.get(1));\n  }\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">15 15<br \/>\na a<br \/>\n16<br \/>\n35<\/div>\n<p>As you can see both primitive data types and objects have the same values. You can use obj in place of num wherever you need to pass the value of num as an object.<\/p>\n<h4>2. Unboxing<\/h4>\n<p>Java Unboxing is the reverse process of Autoboxing. The process to convert the wrapper class object into its corresponding primitive data type is called Java Unboxing.<\/p>\n<p><strong>Code to understand Unboxing in Java:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.techvidvan.wrapperclasses;\nimport java.util.ArrayList;\npublic class UnboxingExample\n{\n  public static void main(String[] args)\n  {\n    Character character = 'R'; \/\/Autoboxing\n    char value = character; \/\/Unboxing\n    System.out.println(value);\n\n    ArrayList&lt;Integer&gt; arrayList = new ArrayList&lt;Integer&gt;();\n    \/\/Autoboxing\n    arrayList.add(50);\n    \/\/Unboxing object into int value\n    int num = arrayList.get(0);\n    System.out.println(num);\n  }\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">R<br \/>\n50<\/div>\n<h3>Implementing Wrapper class in Java<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.techvidvan.wrapperclasses;\npublic class WapperClassDemo\n{\n  public static void main(String[] args)\n  {\n    \/\/ byte data type\n    byte byteVar = 5;\n    \/\/ wrapping around Byte object\n    Byte byteobj = new Byte(byteVar);\n\n    \/\/ int data type\n    int intVar = 33;\n    \/\/wrapping around Integer object\n    Integer intobj = new Integer(intVar);\n\n    \/\/ float data type\n    float floatVar = 16.8f;\n    \/\/ wrapping around Float object\n    Float floatobj = new Float(floatVar);\n\n    \/\/ double data type\n    double doubleVar = 496.87;\n    \/\/ Wrapping around Double object\n    Double doubleobj = new Double(doubleVar);\n\n    \/\/ char data type\n    char charVar='s';\n    \/\/ wrapping around Character object\n    Character charobj=charVar;\n\n    \/\/ printing the values from objects\n    System.out.println(\"Values of Wrapper objects (printing as objects)\");\n    System.out.println(\"Byte object byteobj: \" + byteobj);\n    System.out.println(\"Integer object intobj: \" + intobj);\n    System.out.println(\"Float object floatobj: \" + floatobj);\n    System.out.println(\"Double object doubleobj: \" + doubleobj);\n    System.out.println(\"Character object charobj: \" + charobj);\n\n    \/\/ objects to data types (retrieving data types from objects)\n    \/\/ unwrapping objects to primitive data types\n    byte unwrappingByte = byteobj;\n    int unwrappingInt = intobj;\n    float unwrappingFloat = floatobj;\n    double unwrappingDouble = doubleobj;\n    char unwrappingChar = charobj;\n\n    System.out.println(\"Unwrapped values \");\n    System.out.println(\"byte value, unwrapped Byte: \" + unwrappingByte);\n    System.out.println(\"int value, unwrapped Int: \" + unwrappingInt);\n    System.out.println(\"float value, unwrapped Float: \" + unwrappingFloat);\n    System.out.println(\"double value, unwrapped Double: \" + unwrappingDouble);\n    System.out.println(\"char value, unwrapped Char: \" + unwrappingChar);\n  }\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Values of Wrapper objects (printing as objects)<br \/>\nByte object byteobj: 5<br \/>\nInteger object int obj: 33<br \/>\nFloat object floatobj: 16.8<br \/>\nDouble object double bj: 496.87<br \/>\nCharacter object charobj: s<br \/>\nUnwrapped values<br \/>\nbyte value, unwrapped Byte: 5<br \/>\nint value, unwrapped Int: 33<br \/>\nfloat value, unwrapped Float: 16.8<br \/>\ndouble value, unwrapped Double: 496.87<br \/>\nchar value, unwrapped Char: s<\/div>\n<h3>Methods of Wrapper Class in Java<\/h3>\n<p>The following is the list of some methods that all the subclasses of the <strong>Number<\/strong> class implements:<\/p>\n<table class=\"tv-table-center\">\n<tbody>\n<tr>\n<td><b>S.No.<\/b><\/td>\n<td><b>Method\u00a0<\/b><\/td>\n<td><b>Method Description<\/b><\/td>\n<\/tr>\n<tr>\n<td>1.<\/td>\n<td><span style=\"font-weight: 400\">typeValue()<\/span><\/td>\n<td><span style=\"font-weight: 400\">Returns the Converted value of this Number object to the specified data type.<\/span><\/td>\n<\/tr>\n<tr>\n<td>2.<\/td>\n<td><span style=\"font-weight: 400\">compareTo()<\/span><\/td>\n<td><span style=\"font-weight: 400\">It compares this Number object to the specified argument.<\/span><\/td>\n<\/tr>\n<tr>\n<td>3.<\/td>\n<td><span style=\"font-weight: 400\">equals()<\/span><\/td>\n<td><span style=\"font-weight: 400\">It checks whether this Number object is equal to the specified argument.<\/span><\/td>\n<\/tr>\n<tr>\n<td>4.<\/td>\n<td><span style=\"font-weight: 400\">valueOf()<\/span><\/td>\n<td><span style=\"font-weight: 400\">Returns an Integer object holding the specified primitive type value.<\/span><\/td>\n<\/tr>\n<tr>\n<td>5.<\/td>\n<td><span style=\"font-weight: 400\">toString()<\/span><\/td>\n<td><span style=\"font-weight: 400\">Returns a String object holding the value of a specified Integer type argument.<\/span><\/td>\n<\/tr>\n<tr>\n<td>6.<\/td>\n<td><span style=\"font-weight: 400\">parseInt()<\/span><\/td>\n<td><span style=\"font-weight: 400\">Retrieves the primitive data type of a specified String.<\/span><\/td>\n<\/tr>\n<tr>\n<td>7.<\/td>\n<td><span style=\"font-weight: 400\">abs()<\/span><\/td>\n<td><span style=\"font-weight: 400\">Returns the absolute value of the specified argument.<\/span><\/td>\n<\/tr>\n<tr>\n<td>8.<\/td>\n<td><span style=\"font-weight: 400\">ceil()<\/span><\/td>\n<td><span style=\"font-weight: 400\">Returns the smallest integer that is equal to or greater than the specified argument in double format.<\/span><\/td>\n<\/tr>\n<tr>\n<td>9.<\/td>\n<td><span style=\"font-weight: 400\">floor()<\/span><\/td>\n<td><span style=\"font-weight: 400\">Returns the largest integer that is equal to or less than the specified argument in double format.<\/span><\/td>\n<\/tr>\n<tr>\n<td>10.<\/td>\n<td><span style=\"font-weight: 400\">round()<\/span><\/td>\n<td><span style=\"font-weight: 400\">Returns the closest long or int according to the return type of the method.<\/span><\/td>\n<\/tr>\n<tr>\n<td>11.<\/td>\n<td><span style=\"font-weight: 400\">min()<\/span><\/td>\n<td><span style=\"font-weight: 400\">Returns the smaller between two arguments.<\/span><\/td>\n<\/tr>\n<tr>\n<td>12.<\/td>\n<td><span style=\"font-weight: 400\">max()<\/span><\/td>\n<td><span style=\"font-weight: 400\">Returns the larger between the two arguments.<\/span><\/td>\n<\/tr>\n<tr>\n<td>13.<\/td>\n<td><span style=\"font-weight: 400\">exp()<\/span><\/td>\n<td><span style=\"font-weight: 400\">Returns e to the power of the argument, i.e. base of the natural logarithms.<\/span><\/td>\n<\/tr>\n<tr>\n<td>14.<\/td>\n<td><span style=\"font-weight: 400\">log()<\/span><\/td>\n<td><span style=\"font-weight: 400\">Returns the natural logarithm of the specified argument.<\/span><\/td>\n<\/tr>\n<tr>\n<td>15.<\/td>\n<td><span style=\"font-weight: 400\">pow()<\/span><\/td>\n<td><span style=\"font-weight: 400\">Returns the result of the first argument raised to the power of the second argument.<\/span><\/td>\n<\/tr>\n<tr>\n<td>16.<\/td>\n<td><span style=\"font-weight: 400\">sqrt()<\/span><\/td>\n<td><span style=\"font-weight: 400\">Returns the square root of the specified argument.<\/span><\/td>\n<\/tr>\n<tr>\n<td>17.<\/td>\n<td><span style=\"font-weight: 400\">sin()<\/span><\/td>\n<td><span style=\"font-weight: 400\">Returns the value of sine of the specified double value.<\/span><\/td>\n<\/tr>\n<tr>\n<td>18.<\/td>\n<td><span style=\"font-weight: 400\">cos()<\/span><\/td>\n<td><span style=\"font-weight: 400\">Returns the value of the cosine of the specified double value.<\/span><\/td>\n<\/tr>\n<tr>\n<td>19.<\/td>\n<td><span style=\"font-weight: 400\">tan()<\/span><\/td>\n<td><span style=\"font-weight: 400\">Returns the value of the tangent of the specified double value.<\/span><\/td>\n<\/tr>\n<tr>\n<td>20.<\/td>\n<td><span style=\"font-weight: 400\">asin()<\/span><\/td>\n<td><span style=\"font-weight: 400\">Returns the value of the arcsine of the specified double value.<\/span><\/td>\n<\/tr>\n<tr>\n<td>21.<\/td>\n<td><span style=\"font-weight: 400\">acos()<\/span><\/td>\n<td><span style=\"font-weight: 400\">Returns the value of the arccosine of the specified double value.<\/span><\/td>\n<\/tr>\n<tr>\n<td>22.<\/td>\n<td><span style=\"font-weight: 400\">atan()<\/span><\/td>\n<td><span style=\"font-weight: 400\">Returns the value of the arctangent of the specified double value.<\/span><\/td>\n<\/tr>\n<tr>\n<td>23.<\/td>\n<td><span style=\"font-weight: 400\">toDegrees()<\/span><\/td>\n<td><span style=\"font-weight: 400\">Converts the value of the argument to degrees.<\/span><\/td>\n<\/tr>\n<tr>\n<td>24.<\/td>\n<td><span style=\"font-weight: 400\">toRadians()<\/span><\/td>\n<td><span style=\"font-weight: 400\">Converts the value of the argument to radians.<\/span><\/td>\n<\/tr>\n<tr>\n<td>25.<\/td>\n<td><span style=\"font-weight: 400\">random()<\/span><\/td>\n<td><span style=\"font-weight: 400\">This method returns a random number.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Code to illustrate some methods of wrapper class:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.techvidvan.wrapperclasses;\npublic class WrapperDemo\n{\n  public static void main (String args[])\n  {\n    Integer intObj1 = new Integer (25);\n    Integer intObj2 = new Integer (\"25\");\n    Integer intObj3= new Integer (35);\n\n    \/\/compareTo demo\n    System.out.println(\"Comparing using compareTo Obj1 and Obj2: \" + intObj1.compareTo(intObj2));\n    System.out.println(\"Comparing using compareTo Obj1 and Obj3: \" + intObj1.compareTo(intObj3));\n\n    \/\/Equals demo\n    System.out.println(\"Comparing using equals Obj1 and Obj2: \" + intObj1.equals(intObj2));\n    System.out.println(\"Comparing using equals Obj1 and Obj3: \" + intObj1.equals(intObj3));\n    Float f1 = new Float(\"2.25f\");\n    Float f2 = new Float(\"20.43f\");\n    Float f3 = new Float(2.25f);\n    System.out.println(\"Comparing using compare f1 and f2: \" +Float.compare(f1,f2));\n    System.out.println(\"Comparing using compare f1 and f3: \" +Float.compare(f1,f3));\n\n    \/\/Addition of Integer with Float\n    Float f = intObj1.floatValue() + f1;\n    System.out.println(\"Addition of intObj1 and f1: \"+ intObj1 +\"+\" +f1+\"=\" +f );\n  }\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Comparing using compareTo Obj1 and Obj2: 0<br \/>\nComparing using compareTo Obj1 and Obj3: -1<br \/>\nComparing using equals Obj1 and Obj2: true<br \/>\nComparing using equals Obj1 and Obj3: false<br \/>\nComparing using compare f1 and f2: -1<br \/>\nComparing using compare f1 and f3: 0<br \/>\nAddition of intObj1 and f1: 25+2.25=27.25<\/div>\n<h3>Summary<\/h3>\n<p>Wrapper classes are useful to convert the primitive data types into the objects and vice versa. Coming to the end of this article, we learned the importance of wrapper classes in Java. We covered the concepts of Autoboxing and Unboxing in Java with examples.<\/p>\n<p>We also studied various methods present in Java Wrapper classes and also implemented some methods. This article will surely help you to understand the detailed concept behind wrapper classes in Java.<\/p>\n<p>Thank you for reading our article. Do share your feedback through the comment section below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Java is not a purely object-oriented programming language, the reason being it works on primitive data types. These eight primitive data types int, short, byte, long, float, double, char and, boolean are not objects.&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":77513,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[183],"tags":[2002,2003,2004,2005,1704,2006,2007,2008,2009,2010,2011,2012],"class_list":["post-77198","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","tag-advantages-of-wrapper-class-in-java","tag-creating-wrapper-objects-in-java","tag-implementation-of-java-wrapper-class","tag-java-autoboxing-and-unboxing","tag-java-wrapper-class","tag-java-wrapper-class-example","tag-java-wrapper-class-methods","tag-java-wrapper-class-needs","tag-java-wrapper-class-types","tag-use-of-wrapper-class-in-java","tag-wrapper-class-in-java","tag-wrapper-java"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Wrapper Class in Java - Learn Autoboxing &amp; Unboxing with Coding Examples - TechVidvan<\/title>\n<meta name=\"description\" content=\"Learn the concept of Wrapper Class in Java along with its Implementation, benefits &amp; methods. Also, explore Autoboxing and Unboxing in Java with examples.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/java-wrapper-class\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Wrapper Class in Java - Learn Autoboxing &amp; Unboxing with Coding Examples - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"Learn the concept of Wrapper Class in Java along with its Implementation, benefits &amp; methods. Also, explore Autoboxing and Unboxing in Java with examples.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/java-wrapper-class\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-03-16T04:45:05+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/03\/advantages-of-wrapper-class-in-java.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"802\" \/>\n\t<meta property=\"og:image:height\" content=\"420\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Wrapper Class in Java - Learn Autoboxing &amp; Unboxing with Coding Examples - TechVidvan","description":"Learn the concept of Wrapper Class in Java along with its Implementation, benefits & methods. Also, explore Autoboxing and Unboxing in Java with examples.","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:\/\/techvidvan.com\/tutorials\/java-wrapper-class\/","og_locale":"en_US","og_type":"article","og_title":"Wrapper Class in Java - Learn Autoboxing &amp; Unboxing with Coding Examples - TechVidvan","og_description":"Learn the concept of Wrapper Class in Java along with its Implementation, benefits & methods. Also, explore Autoboxing and Unboxing in Java with examples.","og_url":"https:\/\/techvidvan.com\/tutorials\/java-wrapper-class\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2020-03-16T04:45:05+00:00","og_image":[{"width":802,"height":420,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/03\/advantages-of-wrapper-class-in-java.jpg","type":"image\/jpeg"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/java-wrapper-class\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-wrapper-class\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"Wrapper Class in Java &#8211; Learn Autoboxing &amp; Unboxing with Coding Examples","datePublished":"2020-03-16T04:45:05+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-wrapper-class\/"},"wordCount":1367,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-wrapper-class\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/03\/advantages-of-wrapper-class-in-java.jpg","keywords":["advantages of wrapper class in java","Creating Wrapper Objects in Java","implementation of Java Wrapper class","Java Autoboxing and Unboxing","Java Wrapper class","Java Wrapper Class Example","Java Wrapper Class Methods","Java Wrapper Class Needs","Java Wrapper Class Types","Use of wrapper class in java","wrapper class in Java","Wrapper Java"],"articleSection":["Java Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/java-wrapper-class\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/java-wrapper-class\/","url":"https:\/\/techvidvan.com\/tutorials\/java-wrapper-class\/","name":"Wrapper Class in Java - Learn Autoboxing &amp; Unboxing with Coding Examples - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-wrapper-class\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-wrapper-class\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/03\/advantages-of-wrapper-class-in-java.jpg","datePublished":"2020-03-16T04:45:05+00:00","description":"Learn the concept of Wrapper Class in Java along with its Implementation, benefits & methods. Also, explore Autoboxing and Unboxing in Java with examples.","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-wrapper-class\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/java-wrapper-class\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/java-wrapper-class\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/03\/advantages-of-wrapper-class-in-java.jpg","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/03\/advantages-of-wrapper-class-in-java.jpg","width":802,"height":420,"caption":"Java Wrapper Class Advantages"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/java-wrapper-class\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Wrapper Class in Java &#8211; Learn Autoboxing &amp; Unboxing with Coding Examples"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/77198","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=77198"}],"version-history":[{"count":0,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/77198\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/77513"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=77198"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=77198"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=77198"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}