Mombu the Programming Forum sponsored links

Go Back   Mombu the Programming Forum > Programming > How to: create a list of objects?
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 18th April 03:14
zootal
External User
 
Posts: 1
Default 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
  Reply With Quote


  sponsored links


2 18th April 03:14
tia
External User
 
Posts: 1
Default 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
  Reply With Quote
3 27th April 14:00
marc
External User
 
Posts: 1
Default How to: create a list of objects?


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/
  Reply With Quote
4 27th April 14:00
zootal
External User
 
Posts: 1
Default How to: create a list of objects?


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?
  Reply With Quote
5 27th April 14:00
paul hamaker
External User
 
Posts: 1
Default How to: create a list of objects?


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
  Reply With Quote
6 27th April 14:00
ook
External User
 
Posts: 1
Default How to: create a list of objects?


Nice, thank you
  Reply With Quote
Reply


Thread Tools
Display Modes




Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666