aspose file tools
The moose likes Beginning Java and the fly likes Arranging the element in TreeMap Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Arranging the element in TreeMap" Watch "Arranging the element in TreeMap" New topic
Author

Arranging the element in TreeMap

mohan kumar
Greenhorn

Joined: Apr 16, 2007
Posts: 11
Hi Friends,
i am my work area i am facing a problem like we need to show the month in a drop down with the options order like :

CurrentMonth
Apr-2007
Mar-2007
Feb-2007

For this i am using TreeMap.
when i run the code i am getting in other order like:

Apr-2007
CurrentMonth
Feb-2007
Mar-2007

Can somebody help me in this issue.Waiting for your solution.

Thanks
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2341
By default, Strings are sorted alphabetically.

You'll need to write your own Comparator to order them chronologically.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

"leeboo,"

Welcome to JavaRanch!

Please revise your display name to meet the JavaRanch Naming Policy. To maintain the friendly atmosphere here at the ranch, we like folks to use real (or at least real-looking) names.

You can edit your display name here. Thank you for your prompt attention!

-Marc


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Why are you using a TreeMap and not just a List?


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
mohan kumar
Greenhorn

Joined: Apr 16, 2007
Posts: 11
Why are you using a TreeMap and not just a List?

in map i will get the key of what the user selected and i can proceed with the key.i am taking key for the further manipulation.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Consider using a LinkedHashMap and just add the items in the order you want them to be displayed.
Sidd Kulk
Ranch Hand

Joined: Feb 20, 2007
Posts: 152
If the insertion order is not Important, then probably HashMap wud be the best choice.

Sid
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Arranging the element in TreeMap
 
Similar Threads
NoBrainer...why dosen't it work?
Beta Testers Needed: WebLogic and IBM 484
Date range
HashMaps
Date Function