It's not a secret anymore!*
The moose likes Beginning Java and the fly likes Wrapper class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Wrapper class" Watch "Wrapper class" New topic
Author

Wrapper class

chad stevens
Ranch Hand

Joined: Aug 20, 2002
Posts: 88
Can anyone explain besides converting primitives to objects what a wrapper class is in more detail. I seem to be confused about this term when I read material that talks about advanced topics using wrapper classes.
Arun Boraiah
Ranch Hand

Joined: Nov 28, 2001
Posts: 233
Apart from converting primitives to object wrapper class gives additional functionality which can't not be achieved by just
having it as primitives.
Like conversation of one type of primitives to another type.(int to double with out changing it's original value)
example

Integer oInt = new Integer(i);
..
..
double d = oInt.doubleValue();
Here you can see that orginal int value is retained.

An other important feature of wrapper class is converting string to int,long etc.
Also helps to convert to Octal, Binary, Hex decimal values.


Sharing is learning
chad stevens
Ranch Hand

Joined: Aug 20, 2002
Posts: 88
Thanks your reply. I suppose my confusion came when I was reading something about Collections.
boyet silverio
Ranch Hand

Joined: Aug 28, 2002
Posts: 173
one use for wrapper classes is if, for some reason, you need to store primitive values into a Vector (say to take advantage of certain Vector functions) then you need to convert the primitives into objects before putting them into the Vector.
another is in web apps, where values, in order to be moved from one component (e.g. servlet) to another (e.g. page), need to be turned to objects (e.g. int 'wrapped' with Integer) before they are passed.
chad stevens
Ranch Hand

Joined: Aug 20, 2002
Posts: 88
Hi Boyet.
Ah.. it seems to make more sense now with these examples! Thanks.
boyet silverio
Ranch Hand

Joined: Aug 28, 2002
Posts: 173
welcome, nonetheless.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Wrapper class
 
Similar Threads
wrapper classes
wrapper classes
Wrapper Class ?
Wrapper
Wrapper Classes