Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2006

Tip: Looking for answers? Try searching our database.

TreeMap printout order

Thread view: 
chunji08@gmail.com - 08 Mar 2006 01:20 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 ?

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



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.