What are wrapper classes in Java?

Java 8Object Oriented ProgrammingProgramming

Wrapper classes are those whose objects wraps a primitive data type within them.

In the java.lang package java provides a separate class for each of the primitive data types namely Byte, Character, Double, Integer, Float, Long, Short.

At the time of instantiation, these classes accept a primitive datatype directly, or in the form of String.

Wrapper classes provide methods to, convert primitive datatypes within them to String objects and, to compare them with other objects etc.

Using wrapper classes, you can also add primitive datatypes to various Collection objects such as ArrayList, HashMap etc. You can also pass primitive values over a network using wrapper classes.

Published on 05-Jan-2018 17:33:55