AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to: create a list of objects?

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Discussions
View previous topic :: View next topic  
Author Message
Zootal
Guest





PostPosted: Tue Jan 16, 2007 8:10 am    Post subject: How to: create a list of objects? Reply with 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
tia
Guest





PostPosted: Wed Jan 17, 2007 10:18 pm    Post subject: Re: How to: create a list of objects? Reply with 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:

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





PostPosted: Wed Jan 17, 2007 10:51 pm    Post subject: Re: How to: create a list of objects? Reply with quote



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





PostPosted: Fri Jan 19, 2007 7:50 am    Post subject: Re: How to: create a list of objects? Reply with quote

"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





PostPosted: Fri Jan 19, 2007 8:10 am    Post subject: Re: How to: create a list of objects? Reply with quote

For Collection examples, see :
http://javalessons.com/cgi-bin/fun/java-tutorials-main.cgi?sub=adv&ses=ao789
: a8 thru a12-5 and
http://www.exampledepot.com/egs/java.util/pkg.html
--
http://javalessons.com Paul Hamaker, SEMM
Teaching ICT since 1987
Back to top
Ook
Guest





PostPosted: Sat Jan 20, 2007 8:10 am    Post subject: Re: How to: create a list of objects? Reply with quote

"Paul Hamaker" <ph (AT) semm (DOT) tmfweb.nl> wrote in message
news:1169194094.431281.73510 (AT) v45g2000cwv (DOT) googlegroups.com...
Quote:
For Collection examples, see :
http://javalessons.com/cgi-bin/fun/java-tutorials-main.cgi?sub=adv&ses=ao789
: a8 thru a12-5 and
http://www.exampledepot.com/egs/java.util/pkg.html
--
http://javalessons.com Paul Hamaker, SEMM
Teaching ICT since 1987



Nice, thank you Smile
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Discussions All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.