This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

using item in arraylist as order  RSS feed

 
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.
 
Marshal
Posts: 60116
188
  • 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.
 
author and iconoclast
Sheriff
Posts: 24220
40
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?
 
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: 60116
188
  • 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.
 
author
Bartender
Posts: 3280
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!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!