Let\'s say that I need to generate variables to hold some input from the user (I don\'t know how many they are). Without using Array
, ArrayList
(an
Naming variables like that looks very 1980-ish. Meaning pre object oriented programming. So if you ever build software for a living - DON'T DO THIS.
But since it seems to be homework...
When we're talking about a named variable in Java, we mean something that's compiled. Unlike in some scripting languages there is no easy way to do this in Java.
So either you use a runtime compiled class like Markus Lausberg suggested.
Or you cheat and use the Java Scripting API and make use of the scripting languages. That way you can create code (in a String) at runtime.