• Post Reply Bookmark Topic Watch Topic
  • New Topic

using item in arraylist as order  RSS feed

 
Lucas Franceschi
Ranch Hand
Posts: 106
Mac Mac OS X Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Marshal
Posts: 56593
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't sort a HashMap. There are other Map implementations which can be sorted, see this interface.
 
Lucas Franceschi
Ranch Hand
Posts: 106
Mac Mac OS X Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it needs to be a hashmap.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Lucas Franceschi
Ranch Hand
Posts: 106
Mac Mac OS X Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Lucas Franceschi
Ranch Hand
Posts: 106
Mac Mac OS X Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 106
Mac Mac OS X Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Posts: 56593
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 106
Mac Mac OS X Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok, i'm jsut starting at javaranch.
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No worries Lucas, we like to keep threads around so that people who perform searches can find solutions to similar problems, happy coding!
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!