Java是否支持变量变量? [英] Does Java support variable variables?
本文介绍了Java是否支持变量变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如在PHP中:
<?php
$a = 'hello';
$$a = 'world';
echo $hello;
// Prints out "world"
?>
我需要动态创建一个未知数量的HashMaps(每个都放在一个arraylist中) 。请说是否有更简单或更以Java为中心的方式。谢谢。
I need to create an unknown number of HashMaps on the fly (which are each placed into an arraylist). Please say if there's an easier or more Java-centric way. Thanks.
推荐答案
你能做的最好的就是拥有HashMaps的HashMap。例如:
The best you can do is have a HashMap of HashMaps. For example:
Map<String,Map<String,String>> m = new HashMap<String,Map<String,String>>();
// not set up strings pointing to the maps.
m.put("foo", new HashMap<String,String>());
这篇关于Java是否支持变量变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文