This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Customer Requirements for Developers and have Marcho Behler on-line!
See this thread for details.
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


Win a copy of Customer Requirements for Developers this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What is a "wrapper" class" Watch "What is a "wrapper" class" New topic
Author

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?
Thanks.
Thomas
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="http://www.cise.ufl.edu/~sih" target="_blank" rel="nofollow">www.cise.ufl.edu/~sih</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 ]
 
jQuery in Action, 3rd edition
 
subject: What is a "wrapper" class
 
It's not a secret anymore!