File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes What is a Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What is a "wrapper" class" Watch "What is a "wrapper" class" New topic

What is a "wrapper" class

Thomas Markl
Ranch Hand

Joined: Mar 08, 2001
Posts: 192
Can anybody explain what a wrapper class is and how we use it?
Sayed Ibrahim Hashimi
Ranch Hand

Joined: May 17, 2001
Posts: 148
A wrapper class is a class that serves the sole purpose of holding something and adding some functionality to it.
In Java since the primitaves (like ints,floats,chars...) are not objects so if you want to treat them like one then you have to put use a wrapper class.
So lets say that i want to create a Vector of ints, the problem is a Vector only holds Objects not primitives. So what I will do is put all the ints in an Integer wrapper and use that. Example:

Hope this clears up some issues you are having.

SCJP 1.4<br /><a href="" target="_blank" rel="nofollow"></a>
Anthony Villanueva
Ranch Hand

Joined: Mar 22, 2002
Posts: 1055
Just to add... here's an example of a wrapper class: java.lang.Integer.
[ July 30, 2002: Message edited by: Anthony Villanueva ]
I agree. Here's the link:
subject: What is a "wrapper" class
It's not a secret anymore!