 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Zootal Guest
|
Posted: Tue Jan 16, 2007 8:10 am Post subject: How to: create a list of objects? |
|
|
How would you go about creating a list of objects, where each object can
contain a list of objects, and each sub-object would have various
properties(string, int)?
This is an example. The parent object would be forms of transportation -
car, bike, etc. Each parent object has child objects (chevy, ford, etc.) and
each of these child objects has the same properties (number of doors,
color). How would I represent this data? I need some pointers to start me in
the right direction.
Car - Chevy - 4 doors, green paint
- Ford - 2 doors, purple paint
- Nissan - 3 doors, red paint
Bike - 26 inch, green
- 27 inch, purple |
|
| Back to top |
|
 |
tia Guest
|
Posted: Wed Jan 17, 2007 10:18 pm Post subject: Re: How to: create a list of objects? |
|
|
It depends a lot on how you intend to use the objects. Do you want a
unique set? Do you want them ordered? Do you plan to add or remove items
from the list a lot? Do you want to allow nulls? My top two picks for
holding objects are java.util.Map and java.util.Set of the Collections
framework. Both are capable of holding your objects.
Find out about Collections Framework here:
http://java.sun.com/j2se/1.4.2/docs/guide/collections/index.html
This is a good book which explains the Collections Frameworks very easily:
Java Collections
by John Zukowski
ISBN: 1893115925
written in 2001, but the Collections Framework hasn't changed much since
then, so still very very usable book.
Zootal wrote:
| Quote: | How would you go about creating a list of objects, where each object can
contain a list of objects, and each sub-object would have various
properties(string, int)?
This is an example. The parent object would be forms of transportation -
car, bike, etc. Each parent object has child objects (chevy, ford, etc.) and
each of these child objects has the same properties (number of doors,
color). How would I represent this data? I need some pointers to start me in
the right direction.
Car - Chevy - 4 doors, green paint
- Ford - 2 doors, purple paint
- Nissan - 3 doors, red paint
Bike - 26 inch, green
- 27 inch, purple
|
|
|
| Back to top |
|
 |
Marc Guest
|
Posted: Wed Jan 17, 2007 10:51 pm Post subject: Re: How to: create a list of objects? |
|
|
tia wrote:
| Quote: | It depends a lot on how you intend to use the objects. Do you want a
unique set? Do you want them ordered? Do you plan to add or remove items
from the list a lot? Do you want to allow nulls? My top two picks for
holding objects are java.util.Map and java.util.Set of the Collections
framework. Both are capable of holding your objects.
Find out about Collections Framework here:
http://java.sun.com/j2se/1.4.2/docs/guide/collections/index.html
This is a good book which explains the Collections Frameworks very easily:
|
Also Sams Java in 21 days is highly unrecommended if you're new to Java
in general. Covers lots of collection types; vector, arraylist and
hashtable spring to mind.
--
Marc
For contact information, please see my web site: http://www.iMarc.co.uk/ |
|
| Back to top |
|
 |
Zootal Guest
|
Posted: Fri Jan 19, 2007 7:50 am Post subject: Re: How to: create a list of objects? |
|
|
"Marc" <manictruth-ng (AT) NO_SPAMyahoo (DOT) co.uk> wrote in message
news:1169052640.15036.0 (AT) damia (DOT) uk.clara.net...
| Quote: | tia wrote:
It depends a lot on how you intend to use the objects. Do you want a
unique set? Do you want them ordered? Do you plan to add or remove items
from the list a lot? Do you want to allow nulls? My top two picks for
holding objects are java.util.Map and java.util.Set of the Collections
framework. Both are capable of holding your objects.
Find out about Collections Framework here:
http://java.sun.com/j2se/1.4.2/docs/guide/collections/index.html
This is a good book which explains the Collections Frameworks very
easily:
Also Sams Java in 21 days is highly unrecommended if you're new to Java in
general. Covers lots of collection types; vector, arraylist and hashtable
spring to mind.
|
I'll check that out. One thing I'm having trouble finding is code examples
for the beginner. Sun has a nice tutorial on collections, but where are the
code samples? |
|
| Back to top |
|
 |
Paul Hamaker Guest
|
|
| Back to top |
|
 |
Ook Guest
|
Posted: Sat Jan 20, 2007 8:10 am Post subject: Re: How to: create a list of objects? |
|
|
"Paul Hamaker" <ph (AT) semm (DOT) tmfweb.nl> wrote in message
news:1169194094.431281.73510 (AT) v45g2000cwv (DOT) googlegroups.com...
Nice, thank you  |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|