A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
HOW WRAPPER CLASSES ADD FUNCTIONALITY
Joined: Jul 05, 2006
Jul 12, 2006 00:35:00
This is sai who posted that doubt!
I came to know that using wrapper classes one can change a primitive value into a object!
The reason behind this conversion is that it will add functionality like we can store those primitive objects in collection classes like vectors,list,sets etc.
What i want is that can u plz explain with the help of a javaprg how storing primitive objects in collections classes enhance functionality.
Jesper de Jong
Joined: Aug 16, 2005
Jul 12, 2006 06:43:00
Suppose that somewhere in your program you need to store a list of numbers. You decide to use
to store the numbers.
Now there's a problem:
can only store objects, but primitives are not objects. So you cannot store
s directly in an
The solution is: You wrap each
object, and you store those Integer objects in the
. So the wrapper class Integer makes it possible to store a list of numbers.
Java Beginners FAQ
JavaRanch SCJP FAQ
The Java Tutorial
Java SE 7 API documentation
- My blog about Scala
Joined: Dec 15, 2005
Jul 12, 2006 07:32:00
And why would you want an
instead of int? Because ArrayLists are resizable while arrays (int) are not.
rocket mass heater
subject: HOW WRAPPER CLASSES ADD FUNCTIONALITY
A SIMPLE DOUBT REG WRAPPER CLASSES!
doubt about strings creation
Time to revisit the primitive immutable wrapper objects in the java.lang package?
can we add primitive variables in ArrayList or just objects?
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2013