• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

using item in arraylist as order

 
Ranch Hand
Posts: 106
Mac Mac OS X Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it needs to be a hashmap.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok, i'm jsut starting at javaranch.
 
author
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic