DATAs are being put in a TreeMap, how could I make sure that these
datas are being print out in the order they are read in ?
For example, I have datas as:
"07/20/2005", "NY",
"06/01/2005", "MA,
"01/01/2006", "CA".
The output should be the same as above, NOT
"01/01/2006", "CA".
"06/01/2005", "MA,
"07/20/2005", "NY",
I have tried different ways, no good. Help if you could !
cji
Ian Pilcher - 08 Mar 2006 02:59 GMT
> DATAs are being put in a TreeMap, how could I make sure that these
> datas are being print out in the order they are read in ?
[quoted text clipped - 10 lines]
>
> I have tried different ways, no good. Help if you could !
Are you using Strings as keys? If so, the map will be sorted by the
lexical value of the Strings -- "01" < "06" < "07". You should be using
a class that handles dates more intelligently, such as Calendar.
HTH

Signature
========================================================================
Ian Pilcher i.pilcher@comcast.net
========================================================================
Roedy Green - 08 Mar 2006 03:53 GMT
On Tue, 07 Mar 2006 20:59:09 -0600, Ian Pilcher
<i.pilcher@comcast.net> wrote, quoted or indirectly quoted someone who
said :
>Are you using Strings as keys?
If you use ISO format yyyy-mm-dd you can get away with string
ordering.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
John C. Bollinger - 08 Mar 2006 05:14 GMT
> DATAs are being put in a TreeMap, how could I make sure that these
> datas are being print out in the order they are read in ?
[quoted text clipped - 10 lines]
>
> I have tried different ways, no good. Help if you could !
TreeMap will return keys, values, and entries in the relevant sort order
for the keys. If you want a Map implementation that returns all of
those in insertion order instead then you should consider LinkedHashMap.

Signature
John Bollinger
jobollin@indiana.edu