-2

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?

user2278811
  • 7
  • 1
  • 3

2 Answers2

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

Community
  • 1
  • 1
codefi
  • 406
  • 1
  • 6
  • 17