What is wrapper class in Java? tccicomputercoaching.com

Page 1

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


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.
What is wrapper class in Java? tccicomputercoaching.com by Rosario Riley - Issuu