Friday, 15 April 2011

collections - Using Set or Map for object ordered to a value Java -



collections - Using Set or Map for object ordered to a value Java -

edit more detailed description of function:

i have hashset filled specific object named symbol. specific function iterates through symbols. function specify energy cost of every single symbol , homecoming this. want create new set/map , save symbols in it, ordered energy cost. next algorithm takes symbol biggest energy cost , set in list limited in cases of energy cost. when list full, algorithm ends.

what should utilize save energy cost , symbol? should able energy cost , symbol.

i thought sortedmap , order through guava.collection here:

http://stackoverflow.com/a/3420912

but don't know if best solution? maybe set improve kind of problem?

if have understood want do, need is:

ensure symbol class implements comparable interface. instead set (hashset), utilize sortedset (treeset).

if set fulfills needings, don't alter map, maintain simple ;). maps useful when need random access.

java collections map set

No comments:

Post a Comment