Hash Table Map - updating values

寵の児 提交于 2019-12-12 01:25:41

问题


I am just using a hash table to remember which complementary colours appear in an image.

Anyway so I get the current value count:

Float count = complementaryColour.get(complementaryString[1] + " and " + colourName);

and now I want to change count, so I do:

count += (Float)((frequency/width*height)*total_distance);

and put it back

complementaryColour.put(complementaryString[1] + " and " + colourName, count);

Yet sadly it doesn't like this! It says I need to create a float count, and then when I look at the line putting it back in the hashtable it says it cannot be resolved to a variable.

I have seen this done before, but only when we have Integer count... then count++; this can then be returned to the hashtable!


回答1:


As per your question your Hashtable is like below.

Map <String , Float> complementaryColour=new Hashtable<String, Float >();

Try This

float f=(float) ((frequency/width*height)*total_distance);
lCount+=f;


来源:https://stackoverflow.com/questions/11541771/hash-table-map-updating-values

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!