• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to extract key and value of a hashMap without loop through the hashmap key by key?  RSS feed

 
L Willie
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for example:
want to program an e-dictionaty

Hashmap
key is A,B,C ........untill Z
value would be serial of word based on key.

if the user select "Z",i want to get related value directly without loop 26 times from A till Z.

for my case(not e-dictionary),the hashmap might have thousand of keys.it is time consuming and effect the performance.


thank you
 
Yosi Hendarsjah
Ranch Hand
Posts: 166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have (know) the key, you don't need to iterate the keys. You can directly get the value. Just use the method "get(Object key)".

Have I answered your question?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As mentioned, just get the value located at the key: map.get(keyValue). That's kind of the point of maps.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!