0

I have the variable X, which is constantly changing. How would I be able to declare a new String named after the value of variable X? I am using this in a while loop, where each cycle, I need to temporarily declare a variable to hold information.

1 Answers1

0

What you're trying to do isn't possible. The compiler needs to know the names of all variable names at compile time, but your loop won't execute until runtime. Use a HashMap as suggested by PoByBolek and Starfire1337.

Tim
  • 2,027
  • 15
  • 24
  • It **is** possible, see the answers in http://stackoverflow.com/questions/1192534/is-there-away-to-generate-variables-names-dynamically-in-java. Ths doesn't mean it's a good idea though :) – DavidPostill Jul 15 '14 at 10:47