Which Collection class to use ?

I have 6 fields , where all belong to one single element . Similarly for the second element i need again 6 diff fields , so on......

i may need around 300 such elements.

When i retreive an element , i should be able to retreive all 6 fields pertaining to that.., Also i need not have unique fields from one element to other.

Which Collection class should i use...

Thanks in Advance

[412 byte] By [gulura] at [2007-10-3 5:12:58]
# 1

> I have 6 fields , where all belong to one single

> element . Similarly for the second element i need

> again 6 diff fields , so on......

>

> i may need around 300 such elements.

>

> When i retreive an element , i should be able to

> retreive all 6 fields pertaining to that.., Also

> i need not have unique fields from one element to

> other.

>

> Which Collection class should i use...

>

> Thanks in Advance

List! The list will contain user-defined objects which will hold the data for fields.

aniseeda at 2007-7-14 23:19:24 > top of Java-index,Core,Core APIs...
# 2
List is an interface...dunno how you plan to use it....LinkedList is probably what you mean.
DurgeshNayaka at 2007-7-14 23:19:24 > top of Java-index,Core,Core APIs...
# 3
> List is an interface...dunno how you plan to use> it....LinkedList is probably what you mean.I'm pretty sure aniseed knows that. What he meant was that the OP can use an implementation of the List interface; an ArrayList, Vector or a LinkedList.
prometheuzza at 2007-7-14 23:19:24 > top of Java-index,Core,Core APIs...
# 4

> List is an interface...dunno how you plan to use

> it....LinkedList is probably what you mean.

Yes, List is an interface and what I mean is to use anything which obeys that contract. I would use ArrayList, you use LinkedList and someone else might want to use a Vector. It's *still* a List. I might as well define my own class called List and use it, but it would still work the same way.

aniseeda at 2007-7-14 23:19:24 > top of Java-index,Core,Core APIs...
# 5
Thanks all
gulura at 2007-7-14 23:19:24 > top of Java-index,Core,Core APIs...
# 6
Just consider defining a separate class which corresponds to your "elements" has has 6 fields.Fear-of-creating-classes is an anti-pattern and from your requirements it appears much more straightforward to define a new class than to abuse one of the collections classes.
Horst_Ma at 2007-7-14 23:19:24 > top of Java-index,Core,Core APIs...
# 7

> Just consider defining a separate class which

> corresponds to your "elements" has has 6 fields.

>

> Fear-of-creating-classes is an anti-pattern and from

> your requirements it appears much more

> straightforward to define a new class than to abuse

> one of the collections classes.

I already mentioned that in my reply.

aniseeda at 2007-7-14 23:19:24 > top of Java-index,Core,Core APIs...
# 8

> > I have 6 fields , where all belong to one single

> > element . Similarly for the second element i need

> > again 6 diff fields , so on......

> >

> > i may need around 300 such elements.

> >

> > When i retreive an element , i should be able to

> > retreive all 6 fields pertaining to that..,

> Also

> i need not have unique fields from one element to

> other.

>

> Which Collection class should i use...

>

> Thanks in Advance

>

> List! The list will contain user-defined objects

> which will hold the data for fields.

Also depends on his retrieval criterion. If he wants to retrieve a specific object based on a unique identifier, I would think map would be the way to go with the Unique Identifier as they key.

kilyasa at 2007-7-14 23:19:24 > top of Java-index,Core,Core APIs...
# 9
> Also depends on his retrieval criterion. If he wants> to retrieve a specific object based on a unique> identifier, I would think map would be the way to go> with the Unique Identifier as they key.A point I obviously overlooked. Thanks! :)
aniseeda at 2007-7-14 23:19:24 > top of Java-index,Core,Core APIs...