Sitemap
Javarevisited

A humble place to learn Java and Programming better.

Member-only story

Guide to Wrapper Classes in Java

--

Photo by on

Wrapper classes, also known as wrappers are one of the core features in Java. They’re essentially pre-defined classes that mirror primitive data types like int, double, float, and so on. Since they’re classes, they come with their own utility methods that provide useful operations and functionalities to work with different data types. In this article, we’ll discuss the purpose of wrapper classes in detail, explore conversion between primitive types and wrappers and highlight common pitfalls associated with their use.

Each wrapper class is tailored for specific primitive type. For example:

  • Integer is a wrapper for int.
  • Long is a wrapper for long.
  • Double is a wrapper for double.
  • Boolean is a wrapper for boolean

And the list goes on.

They’re called wrapper classes because they encapsulate or “wrap” primitive data types within objects. This basically allows the primitives to be treated as objects in situations where objects are required.

What’s the point of Wrapper Classes?

Wrapper classes extend the usability of primitive types by providing additional object-related capabilities to be used in situations where primitives do not work. They essentially allow you to

Javarevisited
Javarevisited

Published in Javarevisited

A humble place to learn Java and Programming better.

Firas Ahmed
Firas Ahmed

Written by Firas Ahmed

Hey, I'm a backend developer and I love to share what I learn with the community.

No responses yet