Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

accessing hash map values

Status
Not open for further replies.

stort

Programmer
Feb 17, 2006
10
GB
i currently have a hash map holding keys with values as follows:

key1=AAA value1=10
key2=BBB value2=20
key3=CCC value3=30
key4=DDD value4=40

i also have an array the same size as the hash map (the above size is 4, so the array would also be size 4). lets say it looks like this:

[5][6][7][8]

I would like to multiply value1 (ie 10) with the first value in the array, giving 50, multiply value2 (ie 20) with the second value in the array, giving 120 etc etc for every element in the array/hash map.

How would i go about doing this?

the major problem is that the size of the array and hash map (remember they are the same), will vary. Any help on this would be much appreciated

cheers
 
The order of the hash elements will not stay consistent either. How do you determine which is the "first" hash element? By sorting the keys or the values, or some other way?
 
You would loop through either the hash or the array (or maybe both) using "for" or "foreach" or possibly "map" to do what you want. But as ishnid points out, the hash will need to be sorted first.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top