Dynamic variable names Java

Use a normal HashMap with variable names as strings against their values. Or use a EnumMap with enums as key and your value as values. AFAIK, that’s the closest you can get when using Java. Sure, you can mess around with reflection but IMO the map approach is much more logical.

Leave a Comment