N
news.amnet.net.au
Hi
I am using a TreeMap to store keys with each key referring to an Arraylist
of values.
However perhaps a TreeMap is not quite the right thing to use as it is very
important that when I use an iterator to read out the keys, I get the values
out exactly in the same order as they went in. This is not happening.
I have a bean, with id "mb" which populations the TreeMap with keys, and for
each key, an ArrayList with values.
In my jsp I access the bean's method to population the TreeMap:
TreeMap relationships = mb.getAllRelationships(leftwardfile);
However, when I iterate over the TreeMap, The values do not come our in the
order they went in. Here is my iteration:
Set keySet = relationships.keySet();
Iterator it = keySet.iterator();
while (it.hasNext()) {
[print out ArrayList values for each key]
....it looks like the values come out alphabetically in regards to the keys,
rather than first key in -> first key out.
Is there any other way I can store ArrayLists mapped to keys but where I can
get first key in -> first key out?
Perhaps I need another type of Collection, a List itself perhaps? But a List
does not cater for key -> value relationship and I need the keys to check
that things aren't repeated when the Collection is built. But when I want to
get the values out by iterating over them it needs to be first in -> first
out. Can anyone help with this?
Any help will be greatly appreciated.
Thanks
Hugo
I am using a TreeMap to store keys with each key referring to an Arraylist
of values.
However perhaps a TreeMap is not quite the right thing to use as it is very
important that when I use an iterator to read out the keys, I get the values
out exactly in the same order as they went in. This is not happening.
I have a bean, with id "mb" which populations the TreeMap with keys, and for
each key, an ArrayList with values.
In my jsp I access the bean's method to population the TreeMap:
TreeMap relationships = mb.getAllRelationships(leftwardfile);
However, when I iterate over the TreeMap, The values do not come our in the
order they went in. Here is my iteration:
Set keySet = relationships.keySet();
Iterator it = keySet.iterator();
while (it.hasNext()) {
[print out ArrayList values for each key]
....it looks like the values come out alphabetically in regards to the keys,
rather than first key in -> first key out.
Is there any other way I can store ArrayLists mapped to keys but where I can
get first key in -> first key out?
Perhaps I need another type of Collection, a List itself perhaps? But a List
does not cater for key -> value relationship and I need the keys to check
that things aren't repeated when the Collection is built. But when I want to
get the values out by iterating over them it needs to be first in -> first
out. Can anyone help with this?
Any help will be greatly appreciated.
Thanks
Hugo