Java是否支持变量变量?

比如在PHP中:

 

我需要动态创建一个未知数量的HashMaps(每个都放在一个arraylist中)。 请说是否有更简单或更以Java为中心的方式。 谢谢。

你能做的最好的就是拥有HashMaps的HashMap。 例如:

 Map> m = new HashMap>(); // not set up strings pointing to the maps. m.put("foo", new HashMap()); 

Java不支持您在PHP中所做的事情。

要做类似的事情,你应该只做一个List>并将你的HashMap存储在那里。 您可以使用HashMaps

Java中的“变量变量”是一个数组或List或某种大小不同的数据结构。

不,你会做点什么

 List myMaps = new ArrayList>() 

然后在你的循环中你会做:

 Map newMap = new Hashtable(); //do stuff with newMap myMaps.add(newMap); 

它在java中不称为变量变量。

它被称为reflection。

有关详细信息,请查看java.lang.reflect包文档。

你可以使用reflection做所有这些事情。

Bestoes,

JRH。

你做不到!

没有直接的方法。 数组,reflection等可以提供帮助。