Re: Help with sorting values in a TreeMap
From: Jim McMaster (jim.mcmaster_at_comcast.net)
Date: 02/19/04
- Next message: Valorimatis: "yahoo web site builder, install error: hs_err_pid48319359.log"
- Previous message: Marcus Crafter: "Determining interface implementations during runtime ?"
- In reply to: Wendy S: "Help with sorting values in a TreeMap"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 19 Feb 2004 00:17:17 -0700
Be sure no two items have the same cost center. The second occurrence of
the same key deletes the previous value. I found out the hard way, when I
tried using a TreeMap to sort items by price.
You might want to use Collections.sort(), with the appropriate comparator.
-- -- Jim McMaster mailto: jim.mcmaster@comcast.net "Wendy S" <wendywds@hotmail.com> wrote in message news:c0j8n7$g6e$1@news.asu.edu... > I have a TreeMap that stores a bunch of beans. The 'key' to the Map is a > String, the account number, in the form 32_X_MADN0005, and the 'value' in > the map is an AccountView object whose 'getKey()' method returns the > aforementioned String. > > I use TreeMap so that they sort nicely by the account number. > > But now the users want to be able to choose to sort the accounts by the cost > center, which is the 'MADN0005' part in the example above. So I set about > writing a Comparator. Easy enough... except that TreeMap sorts on the > *keys*, and those are Strings. :( > > I need the Map, because I need to look-up values with the key in other parts > of the app. > > Do I construct an List with the correct Comparator, and use that to display > the items? It shouldn't take up too much extra memory, right? Since both > the List and the Map will just have references to the same AccountView > objects? > > Or do I stop using a String for the key to the Map, and instead use > something else and write Comparators for *that* class? > > Can anyone offer some advice? > > -- > Wendy in Chandler, AZ > >
- Next message: Valorimatis: "yahoo web site builder, install error: hs_err_pid48319359.log"
- Previous message: Marcus Crafter: "Determining interface implementations during runtime ?"
- In reply to: Wendy S: "Help with sorting values in a TreeMap"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|