What is wrapper class in Java? tccicomputercoaching.com Wrapper classes provide a way to use primitive data types (int, boolean, etc..) as objects.
The eight primitive data types byte, short, int, long, float, double, char and boolean are not objects, Wrapper classes are used for converting primitive data types into objects, like int to Integer etc. For example , The Integer is a wrapper class of int primitive type. The wrapper objects hold much more memory compared to primitive types. So use primitive types when you need efficiency and use wrapper class when you need objects instead of primitive types. public class test{ public static void main(String args[]){ //Converting int primitive into Integer object int a=100; Integer obj=Integer.valueOf(a); } } Output: 100 100
System.out.println(a+ " "+ obj);