Does Java support variable variables?

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 does not support what you just did in PHP.

To do something similar you should just make a List<Map<>> and store your HashMaps in there. You could use a HashMap of HashMaps.

A 'variable variable' in Java is an array or List or some sort of data structure with varying size.


Its not called variable variables in java.

Its called reflection.

Take a look at java.lang.reflect package docs for details.

You can do all such sorts of things using reflection.

Bestoes,

jrh.

Tags:

Java