What data type should be used to store multiple collection?

A

angeles

For example, I have multiple sets of following data need to be stored:

date1, time1, month1, year1
date2, time2, month2, year2
.....

Which of following data type should be used: Collection, Array,
ArrayList, List? or others?
then how to extract the data from collections?

Thanks!
 
T

Tony Morris

angeles said:
For example, I have multiple sets of following data need to be stored:

date1, time1, month1, year1
date2, time2, month2, year2
....

Which of following data type should be used: Collection, Array,
ArrayList, List? or others?
then how to extract the data from collections?

Thanks!

http://java.sun.com/docs/books/tutorial/collections/index.html

--
Tony Morris
(BInfTech, Cert 3 I.T.)
Software Engineer
(2003 VTR1000F)
Sun Certified Programmer for the Java 2 Platform (1.4)
Sun Certified Developer for the Java 2 Platform
 
R

Roedy Green

then how to extract the data from collections?

Collections work with objects. You have to bundle your data into
objects. So you might have a date object with methods to get at the
year month day timestamp, etc. You probably don't want something as
big as a Date or Gregorian calendar object. Basically just a timestamp
with a few methods.
 
M

Malcolm Dew-Jones

angeles ([email protected]) wrote:
: For example, I have multiple sets of following data need to be stored:

: date1, time1, month1, year1
: date2, time2, month2, year2

In a language like C, a set of items (date1, time1, month1, year1) would
be stored in a structure.

In Java, instead of a structure, each set of related items would typically
be stored as the instance variables of an object, in a class defined for
this purpose. In the above example you show two sets of related things,
set 1, and set 2. This would require two objects.


: ....

: Which of following data type should be used: Collection, Array, :
ArrayList, List? or others?

You should then use what ever kind of grouping will provide the access you
require with the minimum amount programming effort on your part. If you
must simply examine each object in order then an array would suffice. If
you need to access individual objects based on a key, and perhaps add and
remove items from time to time, then something else would be best.

I suggest you sketch out the code you think you will need on a piece of
paper ahead of time, and write outlines of the routines you will need
using several of the choices, and see which one will do what you want most
easily when you use it.


: then how to extract the data from collections?

I don't remember, I would look it up in my handy dandy java reference
book.
 
A

angeles

Thank you all!

The situation I faced here is a remote client need to get data (sets
of collections) from entity bean which only has local interface, my
session bean has access to entity bean and get collection of Date
objects (which is entity bean object), and the elements of Date object
can be extracted from Date.getxx() method in session bean. my client
needs to know the value of Date.getxx(), but it has no idea of Date
object, so I want session bean returns all values of Date object.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top