| Author |
using item in arraylist as order
|
Lucas Franceschi
Ranch Hand
Joined: Nov 10, 2008
Posts: 106
|
|
ok, this is my problem. i got a hashmap(dados), as the values of this hasmap, I got arraylists. I'm having a great fight with java here. thats b'cuz I need to sort the hashmap, according to one item of the arraylist. what i'm trying to do right now is: but I really (Really.) think that I make it easier. the argument dados(HashMap) is my "master" Hashmap. and sorry if the comments and variable names are in portuguese, i'm brazilian.
|
Lucas Franceschi
Software Developer for SGI Sistemas, lukas1596@gmail.com
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32689
|
|
|
You can't sort a HashMap. There are other Map implementations which can be sorted, see this interface.
|
 |
Lucas Franceschi
Ranch Hand
Joined: Nov 10, 2008
Posts: 106
|
|
|
it needs to be a hashmap.
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24057
|
|
Originally posted by Lucas Franceschi: it needs to be a hashmap.
Well, something somewhere has to give, because by definition, the keys (and values) in a HashMap are not sorted in any user-controlled way, and there's nothing you can do about that. Can you make a new collection containing the sorted keys (or values, I'm confused?) Can you use TreeMap, which lets you store your data sorted?
|
[Jess in Action][AskingGoodQuestions]
|
 |
Lucas Franceschi
Ranch Hand
Joined: Nov 10, 2008
Posts: 106
|
|
ok, I understand. But the case is that I dont need to have an sorted HashMap, I only need to be able to read it in order(ordering it by the [5] position on the arraylists.) anyuone got any soggestions on how to do that?
|
 |
Joanne Neal
Rancher
Joined: Aug 05, 2005
Posts: 3011
|
|
Originally posted by Lucas Franceschi: ok, I understand. But the case is that I dont need to have an sorted HashMap, I only need to be able to read it in order(ordering it by the [5] position on the arraylists.) anyuone got any soggestions on how to do that?
You can't directly iterate over the entries in a Hashmap. You need to extract either the values, keys or key/value pairs into a Collection of some sort, which I think is what you have already done.
|
Joanne
|
 |
Lucas Franceschi
Ranch Hand
Joined: Nov 10, 2008
Posts: 106
|
|
ok joanne, I appreciate the help, I just wanted to know if there was something else to be done. thanks you all guys, helped me a lot. i'm closing the topic...
|
 |
Lucas Franceschi
Ranch Hand
Joined: Nov 10, 2008
Posts: 106
|
|
well I think i'm newbie, and I can't close the topic, so please, this topic is no more useful, please do not waste your time with this... I appeciate the help I got, but that will not be necessary anymore.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32689
|
|
|
We don't close threads unless there is something wrong with them. They simply disappear into the shadows until somebody comes along years later and posts a reply!
|
 |
Lucas Franceschi
Ranch Hand
Joined: Nov 10, 2008
Posts: 106
|
|
|
ok, i'm jsut starting at javaranch.
|
 |
Martijn Verburg
author
Bartender
Joined: Jun 24, 2003
Posts: 3268
|
|
|
No worries Lucas, we like to keep threads around so that people who perform searches can find solutions to similar problems, happy coding!
|
Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
|
 |
 |
|
|
subject: using item in arraylist as order
|
|
|