java - How to get the first four values from Hashmap -


here hashmap<integer, string> storing value, , string associated value. far know, when put value , string hashmap, sort value (because value here integer) in ascending order.
and now, want values rank1 rank4, if not know value of key, how should that?

no, incorrect:

hashmap, sort value

hashmap not order keys. if want that, ought use treemap. uses natural ordering of keys.

if use linkedhashmap, it'll preserve insertion order you. maybe knowing useful.

you'd spend less time here asking questions better answered spending more time reading javadocs classes implement map interface. maybe tour through collections tutorial help, too.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -