开发者

Basic question on passing references of HashMaps

I have defined a HashMap which uses a double type key and another HashMap as value as shown

HashMap<Double, HashMap<Double, String>> HM1 = new HashMap<Double, HashMap<Double, String>>();

Now for each entry of this HashMap I have a reference to a different HashMap; the name of which is derived from the key value of that entry in this HashMap. For example: If my key value in HM1 is 8, then the name of the HashMap to be referenced in "Alpha8". If the key value in HM1 is 6, then the name of the HashMap to be references in "Alpha6". So my syntax in adding these to the HashMap HM1 is HM1.put(8, Alpha8); and HM1.put(6,Alpha6);

My problem:

The key values are pre-defined which I am reading from a text file. He开发者_运维问答nce, I open the file, write a scanner object to pick each value and put it in a double type variable keyvalue. However, to get the value for this key, I defined a string s1 = "Alpha"+keyvalue.toString();

My main problem is how do I pass this string in my put function. Because if I say HM1.put(keyvalue, s1); it is the equivalent of passing a double key and a string value rather than a double key and the reference to another HashMap. For primitive data types, you may be able to wrap but for a HashMap reference, I'm not sure how to do it.


Assuming you have all the possible Alpha* references available to you... I will just put that logic in a simple if condition and do like this

if(keyvalue == 1) 
{
HM1.put(keyvalue, Alpha1)
} 
else(keyvalue == 2)
{

}
--
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜