I know how to name an array when writing a program in Java, but how do I write it to where it ask the user for the name of the array?
Asked
Active
Viewed 124 times
-2
-
2What do you mean by name of the array? Do you mean the variable storing its reference? – Theodoros Chatzigiannakis Apr 24 '13 at 22:55
-
Also what language are we talking about? Write it to a file? – cmd Apr 24 '13 at 22:56
-
1I think you should add more detail, like which programming language and some background on what you are trying to achieve – Ian Kenney Apr 24 '13 at 22:56
-
The"name" of a variable is a lot less important than you realize. Note that multiple variables can refer to the same object. Which one is the one that matters? – Hovercraft Full Of Eels Apr 24 '13 at 23:16
2 Answers
2
Normally you can't change the name of a variable (be it an array, or any other data type) after you've defined it, it's set in stone in the source code of the program. Perhaps you meant something else?

Óscar López
- 232,561
- 37
- 312
- 386
0
You can achieve the desired effect by mapping a String to the array using Map<String,Array>
. See this answer for more details: Assigning variables with dynamic names in Java